我在我的ASP.NET MVC项目中使用JQGrid V5.3(Guriddo JQGrid JS -V5.3.0-2018-02--01(网格工作很好,每个认为都是好的但是,当我想出口电网以表现出色时,我会收到此错误:TypeError:B.URL为null我该如何解决?
我使用" jquery-2.1.1",然后将这些脚本添加到我的项目中:
<script src="~/Scripts/jqgrid/js/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="~/Scripts/jqgrid/src/grid.export.js"></script>
这是我的JavaScript代码:
$(document).ready(function () {
debugger;
LoadCustomerOrders();
});
function LoadCustomerOrders() {
// Make sure IE allows us to load JSON data from the iNorthwind website
jQuery.support.cors = true;
// Load our JSON data, and populate the jqGrid control with it
$("#tblOrders").jqGrid({
url: 'http://www.inorthwind.com/Service1.svc/getOrdersForCustomer/BERGS',
contentType: "application/json",
datatype: "json",
data: "{}",
jsonReader: {
root: "GetOrdersForCustomerResult", //arry containing actual data
id: "OrderID", //index of the column with the PK in it
repeatitems: false
},
mtype: "GET",
colNames: ["ID", "Order Date", "Name",
"Address", "City", "Postcode", "Shipped Date"],
colModel: [
{ name: "OrderID", width: 70, align: "center", search: false },
{ name: "OrderDate", search: true, width: 100 },
{ name: "ShipName", search: true, width: 120 },
{ name: "ShipAddress", search: true, hidden: true },
{ name: "ShipCity", search: true, width: 200 },
{ name: "ShipPostcode", search: true, width: 140 },
{ name: "ShippedDate", search: true, width: 80, align: "center" }
],
pager: "#pager",
width: 'auto',
height: 'auto',
rowNum: 10,
rowList: [],
loadonce: true,
sortable: true,
sortname: "OrderID",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
ignoreCase: true, // Make the "Search" popup search case-insensitive
caption: ""
});
$('#tblOrders').jqGrid('navGrid', '#pager', {
search: true,
searchtext: "Search", // Make the Search icon have a "Search" label next to it
edit: false,
add: false,
del: false,
refresh: false
},
{}, // default settings for edit
{}, // default settings for add
{}, // delete
{
closeOnEscape: true, closeAfterSearch: true, ignoreCase: true, multipleSearch: false, multipleGroup: false, showQuery: false,
sopt: ['cn', 'eq', 'ne'],
defaultSearch: 'cn'
}).navButtonAdd('#pager', {
caption: "Export to Excel",
buttonicon: "ui-icon-disk",
onClickButton: function () {
ExportDataToExcel("#tblOrders");
},
position: "last"
});
}
function ExportDataToExcel(tableCtrl) {
// Export the data from our jqGrid into a "real" Excel 2007 file
// ExportJQGridDataToExcel(tableCtrl, "CustomerOrders.xlsx");
var gridData = $("#tblOrders").jqGrid('getRowData');
var dataToSend = JSON.stringify(gridData);
jQuery("#tblOrders").jqGrid('excelExport', dataToSend);
}
我认为您不使用正确的方法将数据导出到使用Guriddo JQGrid Excel。您使用ExceLexport,它仅向服务器发送参数,并期望在服务器上完成导出。您需要使用ExportToExcel方法。这是文档。请查看此示例
另外一份说明 - 您不需要包含Grid.export.js文件。此文件已包含在您使用的jquery.jqgrid.min文件中。