GithubHelp home page GithubHelp logo

bubdm / asp.net-mvc-jquery-datatables Goto Github PK

View Code? Open in Web Editor NEW

This project forked from altughan09/asp.net-mvc-jquery-datatables

0.0 0.0 0.0 10.88 MB

Price Quotation Table with jQuery Datatables (ASP.NET MVC)

C# 88.77% CSS 9.41% ASP 1.82%

asp.net-mvc-jquery-datatables's Introduction

ASP.NET-MVC-jQuery-Datatables

Price Quotation Table with jQuery Datatables (ASP.NET MVC)

In order to make datatable work, we should place our scripts in the following order.

<link href="https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/dataTables.buttons.min.js" ></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.flash.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.html5.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.print.min.js"></script>

T-SQL Database Code:

CREATE TABLE [dbo].[Table] (
    [QuoteID]      NCHAR (10) NOT NULL,
    [CustomerName] NCHAR (40) NOT NULL,
    [Description]  NCHAR (40) NOT NULL,
    [Quantity]     FLOAT (53) NOT NULL,
    [UnitPrice]    FLOAT (53) NOT NULL,
    [VatRate]      FLOAT (53) NOT NULL,
    [SubTotal]     FLOAT (53) NOT NULL,
    [TotalAmount]  FLOAT (53) NOT NULL,
    PRIMARY KEY CLUSTERED ([QuoteID] ASC)
);

HomeController.cs;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCDatatable.Controllers
{
    public class HomeController : Controller
    {
       public ActionResult Index()
        {
            return View();
        }

        public ActionResult loaddata()
        {
            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                var data = dc.Tables.OrderBy(a => a.QuoteID).ToList();
                return Json(new { data = data }, JsonRequestBehavior.AllowGet);
            }
        }
    }
}

View for Index;

@{
    ViewBag.Title = "Index";
}

<h2>Price Quotation List</h2><br />
<div style="margin:0 auto;">
    <table style="width:100%;" class="display" id="QuoteTable">
        <thead>
            <tr>
                <th>Quote ID</th>
                <th>Customer</th>
                <th>Description</th>
                <th>Quantity</th>
                <th>Unit Price</th>
                <th>VAT/Tax Rate</th>
                <th>Net Offer</th>
                <th>Total</th>
            </tr>
        </thead>
    </table>
</div>


@*Datatable CSS*@
<link href="https://cdn.datatables.net/v/dt/dt-1.10.18/datatables.min.css" rel="stylesheet" />

@*Datatable-buttons CSS*@
<link href="https://cdn.datatables.net/buttons/1.5.4/css/buttons.dataTables.min.css" rel="stylesheet" />

@*jQuery JS*@
@Scripts.Render("~/bundles/jquery")
<script src="~/Scripts/jquery-3.3.1.min.js"></script>

@*Datatable JS*@
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/dataTables.buttons.min.js" ></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.flash.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.html5.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.print.min.js"></script>

<script>
    $(document).ready(function () {
        $.noConflict();
        $('#QuoteTable').DataTable({

            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'copy',
                    title: 'Quote Report'
                },
                {
                    extend: 'csv',
                    title: 'Quote Report'
                },
                 {
                     extend: 'excel',
                     title: 'Quote Report'
                },
                  {
                    extend: 'pdf',
                      title: 'Quote Report'
                },
                   {
                       extend: 'print',
                       title: 'Quote Report'
                }
            ],

            "ajax": {
                "url": "/home/loaddata",
                "type": "GET",
                "datatype": "json",
            },
            "language": {
                "zeroRecords": "No records found to display"
            },
           
            "columns": [
                { "data": "QuoteID", "autoWidth": true },
                { "data": "CustomerName", "autoWidth": true },
                { "data": "Description", "autoWidth": true },
                { "data": "Quantity", "autoWidth": true },
                { "data": "UnitPrice", "autoWidth": true },
                { "data": "VatRate", "autoWidth": true },
                { "data": "SubTotal", "autoWidth": true },
                { "data": "TotalAmount", "autoWidth": true }
            ]
        });
    });
</script>

alt text

alt text

alt text

alt text

asp.net-mvc-jquery-datatables's People

Contributors

altughan09 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.