@{ ViewBag.Title = "List of Products By Categories"; } @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 () { // set jqrid properties $('#list-grid').jqGrid({ url: '/Categories/GridData/', datatype: 'json', mtype: 'GET', colNames: ['Category ID','Category Name','Description'], colModel: [ { name: 'CategoryID', index: 'CategoryID', align: 'right' }, { name: 'CategoryName', index: 'CategoryName', align: 'left' }, { name: 'Description', index: 'Description', align: 'left', sortable: false }, ], pager: $('#list-pager'), rowNum: 5, rowList: [5, 10, 20, 50], sortname: 'CategoryID', sortorder: 'asc', viewrecords: true, caption: 'List of Products By Categories', height: '100%', width: '1200', multiselect: false, onSelectRow: function (ids) { if (ids != null) { $('#list-grid-detail').jqGrid('setGridParam', { url: "/Products/GridDataWithFilters/?filters={\"groupOp\":\"AND\",\"rules\":[{\"field\":\"CategoryID\",\"op\":\"eq\",\"data\":\"" + ids + "\"}]}", page: 1 }); $('#list-grid-detail').jqGrid('setCaption', "List of Products By Category ID: " + ids) .trigger('reloadGrid'); } } }); }); $(function () { // set jqrid properties $('#list-grid-detail').jqGrid({ url: "/Products/GridDataWithFilters/?filters={\"groupOp\":\"AND\",\"rules\":[{\"field\":\"CategoryID\",\"op\":\"eq\",\"data\":\"-1\"}]}", 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' }, { name: 'CategoryID', index: 'CategoryID', align: 'right' }, { 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-detail'), rowNum: 10, rowList: [5, 10, 20, 50], sortname: 'ProductID', sortorder: 'asc', viewrecords: true, height: '100%', width: '1200' }); }); </script> } <h2>@ViewBag.Title</h2> <br /><br /> <table id="list-grid"></table> <div id="list-pager"></div> <br /><br /> <table id="list-grid-detail"></table> <div id="list-pager-detail"></div>