when exporting to excel JqGrid,I Get error "TypeError: b.url is null "
when exporting to excel JqGrid,I Get error "TypeError: b.url is null "
我在 asp.net MVC 项目中使用 jqGrid v5.3(Guriddo jqGrid JS - v5.3.0 - 2018-02-
01)
网格工作得很好,每一个想法都很好
但是当我想将网格导出到 excel 时,出现此错误:
类型错误:b.url 为空
我该如何解决?
我使用 "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 方法。这里是 documentation. Please look at this example
另外一个注意事项 - 您不需要包含 grid.export.js 文件。此文件已包含在您使用的 jquery.jqGrid.min 文件中。
我在 asp.net MVC 项目中使用 jqGrid v5.3(Guriddo jqGrid JS - v5.3.0 - 2018-02- 01) 网格工作得很好,每一个想法都很好 但是当我想将网格导出到 excel 时,出现此错误: 类型错误:b.url 为空 我该如何解决?
我使用 "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 方法。这里是 documentation. Please look at this example
另外一个注意事项 - 您不需要包含 grid.export.js 文件。此文件已包含在您使用的 jquery.jqGrid.min 文件中。