【发布时间】:2014-03-18 22:03:44
【问题描述】:
我正在使用带有子网格功能的 jQGrid,我的键列有日期,当我点击“+”时 subGridRowExpanded 被触发并创建一个子网格
代码在使用其他以数字作为关键字段的列时工作正常,但在使用日期作为关键字段时会抛出错误,例如它的值将是 03/18/2014
“Microsoft JScript 运行时错误:语法错误,无法识别的表达式:#grid_3/18/2014” 我的主网格 ID 是网格
当我使用 GMMNumber 作为 Key 时它可以正常工作,但当我使用 NCChitDate 时它会失败,这是一个具有日期格式值的日期字段..
下面是我的代码:
function LoadNCTRequestGrid() {
var cols = "";
var colmodels = "";
if (!ReqType) {
cols = ['Date', 'NC Chit Print', '2nd Scan Disposition', '%', "Items Merch'd in Place", 'Items On Request', 'Carton Completed', '%', 'Open Balance (Items On Request Carton Complete)'];
colmodels = [{ name: 'NCChitDate', index: 'NCChitDate', width: 300, key: true },
{ name: 'NCChitPrintQty', index: 'NCChitPrintQty', width: 300 },
{ name: 'SecondScanDisp', index: 'SecondScanDisp', width: 300 },
{ name: 'PercentageSecondScanDisp', index: 'PercentageSecondScanDisp', width: 180 },
{ name: 'ItemsMerchandised', index: 'ItemsMerchandised', width: 280 },
{ name: 'ItemsOnRequest', index: 'ItemsOnRequest', width: 280 },
{ name: 'CartonCompleted', index: 'CartonCompleted', width: 280 },
{ name: 'PercentageCartonCompleted', index: 'PercentageCartonCompleted', width: 280 },
{ name: 'OpenBalance', index: 'OpenBalance', width: 280 }
];
}
else{
cols = ['','GMM', 'NC Chit Print', '2nd Scan Disposition', '%', "Items Merch'd in Place", 'Items On Request', 'Carton Completed', '%', 'Open Balance (Items On Request Carton Complete)'];
colmodels = [
{ name: 'GMMNumber', index: 'GMMNumber', width: 300, key:true, hidden:true},
{ name: 'GMMDesc', index: 'GMMDesc', width: 300 },
{ name: 'NCChitPrintQty', index: 'NCChitPrintQty', width: 300 },
{ name: 'SecondScanDisp', index: 'SecondScanDisp', width: 300 },
{ name: 'PercentageSecondScanDisp', index: 'PercentageSecondScanDisp', width: 180 },
{ name: 'ItemsMerchandised', index: 'ItemsMerchandised', width: 280 },
{ name: 'ItemsOnRequest', index: 'ItemsOnRequest', width: 280 },
{ name: 'CartonCompleted', index: 'CartonCompleted', width: 280 },
{ name: 'PercentageCartonCompleted', index: 'PercentageCartonCompleted', width: 280 },
{ name: 'OpenBalance', index: 'OpenBalance', width: 280 }
];
}
$("#grid").jqGrid({
url: '@Url.Action("GetNCTRequest")',
mtype: "POST",
datatype: 'json',
colNames: cols,
colModel: colmodels,
width: 1140,
height: '100%',
rowNum: 5000,
subGrid: true,
afterInsertRow: function (rowId, aData, rowelem) {
var theGrid = $(this);
},
beforeSelectRow: function (rowid, e) {
return false;
},
loadComplete: function () {
$("tr.jqgrow:odd").css("background", "#DDDDDC");
$(".jqgrow:odd").hover(
function () {
$(this).css("background-color", "#E11A2B");
},
function (event) { $(this).css("background-color", "#DDDDDC"); }
);
},
subGridRowExpanded: function (subgridDivId, rowId) {
var subgridTableId = subgridDivId + '_t';
$("#" + subgridDivId).html("<table id='" + subgridTableId + "'></table>");
var cols = "";
var colmodels = "";
if(!ReqType){
cols = ['GMM', 'DIV', 'Dept', 'Vend', 'UPC', 'NC Chit Print', '2nd Scan Disposition', "Items Merch'd in Place", 'Items On Request', 'Carton Completed', 'Open Balance (Items On Request Carton Complete)', 'Carton ID'];
colmodels = [
{ name: 'GMMDesc', index: 'GMMDesc', width: 300 },
{ name: 'DivisionDesc', index: 'DivisionDesc', width: 300 },
{ name: 'DepartmentName', index: 'DepartmentNumber', width: 300 },
{ name: 'VendorID', index: 'VendorID', width: 100 },
{ name: 'UPCNumber', index: 'UPCNumber', width: 100 },
{ name: 'NCChitPrintQty', index: 'NCChitPrintQty', width: 300 },
{ name: 'SecondScanDisp', index: 'SecondScanDisp', width: 300 },
{ name: 'ItemsMerchandised', index: 'ItemsMerchandised', width: 280 },
{ name: 'ItemsOnRequest', index: 'ItemsOnRequest', width: 280 },
{ name: 'CartonCompleted', index: 'CartonCompleted', width: 280 },
{ name: 'OpenBalance', index: 'OpenBalance', width: 280 },
{ name: 'CartonID', index: 'CartonID', width: 100 },
{ name: 'NCChitDate', index: 'NCChitDate', width: 10, key: true, hidden : true }
]
}
else{
cols = ['Date', 'DIV', 'Dept', 'Vend', 'UPC', 'NC Chit Print', '2nd Scan Disposition', "Items Merch'd in Place", 'Items On Request', 'Carton Completed', 'Open Balance (Items On Request Carton Complete)', 'Carton ID'];
colmodels = [
{ name: 'NCChitDate', index: 'NCChitDate', width: 100},
{ name: 'DivisionDesc', index: 'DivisionDesc', width: 150 },
{ name: 'DepartmentName', index: 'DepartmentNumber', width: 200 },
{ name: 'VendorID', index: 'VendorID', width: 50 },
{ name: 'UPCNumber', index: 'UPCNumber', width: 100 },
{ name: 'NCChitPrintQty', index: 'NCChitPrintQty', width: 50 },
{ name: 'SecondScanDisp', index: 'SecondScanDisp', width: 50 },
{ name: 'ItemsMerchandised', index: 'ItemsMerchandised', width: 50 },
{ name: 'ItemsOnRequest', index: 'ItemsOnRequest', width: 100 },
{ name: 'CartonCompleted', index: 'CartonCompleted', width: 50 },
{ name: 'OpenBalance', index: 'OpenBalance', width: 50 },
{ name: 'CartonID', index: 'CartonID', width: 100 }
]
}
$("#" + jQuery.jgrid.jqID(subgridTableId)).jqGrid({
mtype: "POST",
datatype: 'json',
url: encodeURI('@Url.Action("GetnctRequestIndividualDetails")' + '?reqValue=' + rowId),
colNames: cols,
colModel: colmodels,
rowNum: 9999,
height: '100%'
});
$(".ui-icon-carat-1-sw").css("background-image", "none");
}
});
}
【问题讨论】:
-
您使用哪个版本的 jqGrid?在
jquery.jqGrid.src.js的哪个行号中,您会收到错误“无法识别的表达式:#grid_3/18/2014”。您确定该日期作为 id 没有任何重复项吗?无论如何,在所有子网格场景中通常使用idPrefix。哪些输入数据有网格和子网格? 1-2 行输入数据可能会有所帮助。 -
@Oleg 我正在使用 JQgrid-4.5.4,当它尝试创建 SubGrid 时,我在这一行出现错误 -- $("#" + subgridDivId).html("
"); ---- 我的父网格只有一条记录,我正在传递 2014 年 3 月 19 日的密钥 ID 它工作正常如果我将某个数字作为密钥,如我的代码所示,只有在传递 !ReqType 时才会出现此问题以日期为 KEY 字段
标签: asp.net-mvc-3 date jqgrid subgrid