@{ ViewBag.Title = "List of Products"; } @section AdditionalCss { <link rel="stylesheet" href="~/css/ui.jqgrid.min.css" /> } @section AdditionalJavaScript { <script src="~/js/jqgrid-i18n/grid.locale-en.min.js" asp-append-version="true"></script> <script src="~/js/jquery-jqgrid-4.13.2.min.js" asp-append-version="true"></script> <script type="text/javascript"> function supplierIDLink(cellvalue, options, rowObject) { return "<a href='/Suppliers/Details/" + cellvalue + "'>" + cellvalue + "</a>"; } function categoryIDLink(cellvalue, options, rowObject) { return "<a href='/Categories/Details/" + cellvalue + "'>" + cellvalue + "</a>"; } $(function () { $('#list-grid').jqGrid({ url: '/Products/GridData/', datatype: 'json', mtype: 'GET', colNames: ['Product ID','Product Name','Supplier ID','Category ID','Quantity Per Unit','Unit Price','Units In Stock','Units On Order','Reorder Level','Discontinued'], colModel: [ { name: 'ProductID', index: 'ProductID', align: 'right' }, { name: 'ProductName', index: 'ProductName', align: 'left' }, { name: 'SupplierID', index: 'SupplierID', align: 'right', formatter: supplierIDLink }, { name: 'CategoryID', index: 'CategoryID', align: 'right', formatter: categoryIDLink }, { name: 'QuantityPerUnit', index: 'QuantityPerUnit', align: 'left' }, { name: 'UnitPrice', index: 'UnitPrice', align: 'right', formatter: 'currency', formatoptions: { decimalPlaces: 2, prefix: "$"} }, { name: 'UnitsInStock', index: 'UnitsInStock', align: 'right', formatter: 'integer' }, { name: 'UnitsOnOrder', index: 'UnitsOnOrder', align: 'right', formatter: 'integer' }, { name: 'ReorderLevel', index: 'ReorderLevel', align: 'right', formatter: 'integer' }, { name: 'Discontinued', index: 'Discontinued', align: 'center', formatter: 'checkbox' } ], pager: $('#list-pager'), scroll: 1, gridview: true, rownumbers: true, rownumWidth: 20, rowNum: 20, sortname: 'ProductID', sortorder: "asc", viewrecords: true, caption: 'List of Products', height: '250', width: '1200' }); }); </script> } <h2>@ViewBag.Title</h2> <br /><br /> <table id="list-grid"></table> <div id="list-pager"></div>