<script> $(document).ready(function () { $("#btnLook").click(function drawTable() { var grid_selector = "#grid-table"; var itemCategoryId = $("#itemCategoryId").val(); //初始化表格 jQuery(grid_selector).jqGrid({ subGrid: false, subGridOptions: { plusicon: "ace-icon fa fa-plus center bigger-110 blue", minusicon: "ace-icon fa fa-minus center bigger-110 blue", openicon: "ace-icon fa fa-chevron-right center orange" }, url: '/stock/showItem', caption: '商品数据列表', data: {}, postData: { 'itemCategoryId': itemCategoryId }, datatype: "json", mtype: "post", height: 1000, autowidth: true, colNames: ['商品名称', '商品编号', '商品价格', '商品数量', '商品重量', '商品种类'], colModel: [ {name: 'item_name', sortable: false, width: 230}, {name: 'item_barcode', sortable: false,width:200}, {name: 'item_price', index: 'item_sale_date', sortable: false, width: 80}, {name: 'item_num', sortable: false, width: 80}, {name: 'item_weight', sortable: false, width: 80}, {name: 'c_name', sortable: false, width: 80} ], viewrecords: true,//显示总记录数 rowNum: 20, rowList: [10, 20, 30], pager: '#jqGridPager', altRows: false, }) //清空表单数据 重新加载 $(grid_selector).jqGrid('clearGridData'); $(grid_selector).jqGrid('setGridParam', { url: '/stock/showItem', caption: '商品数据列表', data: {}, postData: { 'itemCategoryId': itemCategoryId }, datatype: "json", mtype: 'post', }).trigger('reloadGrid'); }) }) </script> </head> <body> <div id="tooles"> <select class="form-control" id="itemCategoryId" style="width:150px;float: left;margin-top: 25px;margin-left: 20px;"> <option value="" selected="true">全部商品种类</option> <c:forEach items="${itemCategoryList}" var="item"> <option value="${item.id}">${item.name}</option> </c:forEach> </select> <button id="btnLook" class="btn btn-primary" style="margin-top: 20px;margin-left: 20px">查看商品 </button> </div> <table id="grid-table" style="width: auto" class="tsble .table-bordered .table-striped"></table> <div id="jqGridPager"></div> </body>
解决方法:
//清空数据,重新加载。