【发布时间】:2014-01-01 13:50:48
【问题描述】:
将 jqGrid 用作子网格,编辑子网格行就可以了。
但是当尝试添加 SubGrid 行时,idDiscount (FK) 应该与 SubGrid 表单一起发布。
我试过在网上搜索这个,但没有找到关于这个主题的任何内容。
如您所见,在我的主网格中,主键是idDiscount,
在子网格上,主键是 cdDiscount 和 FK idDiscount
使用的代码(修剪)
jQuery(gridSelector).jqGrid({
url: '',
postData: {
action: "MainGrid"
},
editurl: "default.aspx?action=MainGrid",
datatype: 'json',
colNames: ['idDiscount'],
colModel: [{
name: 'idDiscount',
index: 'idDiscount',
hidden: true,
soratable: false,
key: true,
},
subGrid: true,
subGridRowExpanded: function (subgridId, rowId) {
var currentRow = $(gridSelector).jqGrid('getRowData', rowId);
var idDiscount = currentRow.idDiscount;
var subgridTableId, pagerId;
subgridTableId = subgridId + "_t";
pagerId = "p_" + subgridTableId;
$("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table><div id='" + pagerId + "' class='scroll'></div>");
jQuery("#" + subgridTableId).jqGrid({
url: '',
editurl: 'default.aspx?action=SubGrid',
datatype: 'json',
postData: {
action: "SubGrid",
idDiscount: rowId
},
colNames: ['idDiscount', 'cdDiscount'],
colModel: [{
name: 'idDiscount',
index: 'idDiscount',
hidden: true,
editable: true,
editoptions: {
disabled: false,
value: idDiscount,
},
}, {
name: "cdDiscount",
index: "cdDiscount",
key: true,
editable: true,
editrules: {
required: true
}
]
});
});
我的完整subGrudRowExpanded
subGridRowExpanded: function (subgridId, rowId) {
var subgridTableId, pagerId;
subgridTableId = subgridId + "_t";
pagerId = "p_" + subgridTableId;
$("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table><div id='" + pagerId + "' class='scroll'></div>");
jQuery("#" + subgridTableId).jqGrid({
url: '',
editurl: 'default.aspx?action=SubGrid',
datatype: 'json',
postData: { action: "SubGrid", idDiscount: rowId },
colNames: ['Code', 'Percent', 'Title', 'Uses', 'Used', 'From', 'To', 'CreatedBy', ' '],
colModel: [
{ name: "cdDiscount", index: "cdDiscount", key: true, editable: true, editrules: { required: true } },
{ name: "pcDiscount", index: "pcDiscount", editable: true, editrules: { required: true, number:true } },
{ name: "txDescription", index: "txDescription", editable: true },
{ name: "ctUses", width: '60px', classes: 'center', index: "ctUses", editable: false },
{ name: "ctUsed", width: '60px', classes: 'center', index: "ctUsed", editable: false },
{ name: "dtValidFr", width: '100px', classes: 'center', index: "dtValidFr", editable: true, editoptions: { dataInit: function (el) { datePick(el); } }, editrules: { required: true }, sorttype: 'date', formatter: "date", formatoptions: { srcformat: "ISO8601Long", newformat: "ShortDate" } },
{ name: "dtValidTo", width: '100px', classes: 'center', index: "dtValidTo", editable: true, editoptions: { dataInit: function (el) { datePick(el); } }, editrules: { required: true }, sorttype: 'date', formatter: "date", formatoptions: { srcformat: "ISO8601Long", newformat: "ShortDate" } },
{ name: "idUserCreatedBy", index: "idUserCreatedBy" },
{
name: 'actions',
index: '',
width: 80,
fixed: true,
sortable: false,
search: false,
resize: false,
formatter: 'actions',
formatoptions: {
keys: true,
delOptions: { recreateForm: true, beforeShowForm: beforeDeleteCallback },
editformbutton: true,
editOptions: {
recreateForm: true, beforeShowForm: beforeEditCallback,
addEditOptions: {
onclickSubmit: function () {
return { idDiscount: rowId };
}
}
}
}
}
],
rowNum: 10,
rowList: [10, 20, 30],
pager: pagerId,
height: 'auto',
width: '100%',
autowidth: true,
loadComplete: function () {
var table = this;
setTimeout(function() {
styleCheckbox(table);
updatePagerIcons(table);
enableTooltips(table);
}, 0);
}
});
jQuery("#" + subgridTableId).jqGrid('navGrid', "#" + pagerId, jqIcons, jqEditForm, jqNewForm, jqDeleteForm, jqSearchForm, jqViewForm);
},
【问题讨论】:
-
您发布的代码未显示您使用的哪种编辑模式(内联编辑、表单编辑或单元格编辑)。带有
subGridRowExpanded回调的行也被删除。是subGridRowExpanded(subgridId, rowId)吗?您同时使用idDiscount(参见editoptions: {value: idDiscount}???)和rowId。奇怪的是,您在子网格中包含'idDiscount'列。你真的需要它还是只是为了解决你的主要问题? -
是表单编辑。我确实根据需要使用
subGridRowExpanded。我添加了editoptions:{value:idDiscount}作为尝试解决它(从我在网上找到的东西。只是为了让事情清楚,一切正常,唯一的问题是,当向子网格添加一行时,idDiscount 没有与父行的值。