jqGrid 编辑表单预填了错误的值。 (第二次点击时)
我使用 jqGrid 插件。有网格和子网格打开。当我第二次单击以编辑主网格中的行时,字段会填充错误的值。 重现的详细步骤:
- 单击编辑行(主网格行)
- 编辑表单正确填充,确定(参见第一个屏幕)
- 单击“取消”按钮
- 再次单击编辑行
- 编辑表单填充错误(参见第二个屏幕)
这是我的代码:
$(function () {
$("#list").jqGrid({
url: 'Country/CountryListPaged',
editurl: "Country/AddEditDeleteCountry",
datatype: "json",
mtype: 'POST',
colModel: [
{ name: 'idCountry', index: 'idCountry', label: 'Id', width: 100, editable:true, hidden:true },
{ name: 'code', index: 'code', label: 'Код', width: 200, align:'center', editable: true, edittype:'text', editrules:{ required:true} },
{ name: 'title', index: 'title', label: 'Название', width: 300, align: 'center', editable: true, edittype: 'text', editrules: { required: true} }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20],
sortname: 'Title',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Список стран',
height: 'auto',
autowidth: true,
scrollOffset: 0,
hidegrid: false,
subGrid: true,
subGridRowExpanded: function (subgridId, rowId) {
var subgridTableId, pagerId;
subgridTableId = subgridId + "_t";
pagerId = "p_" + subgridTableId;
var tmp = $("#list").getRowData(rowId);
var idCountry = tmp.idCountry;
var countryCode = tmp.code;
$("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table><div id='" + pagerId + "' class='scroll'></div>");
jQuery("#" + subgridTableId).jqGrid({
url: "Country/CountryTranslateVariantsList?idCountry=" + idCountry + "&countryCode=" + countryCode,
editurl: "Country/AddEditDeleteCountryTranslateVariant",
mtype: "POST",
datatype: "json",
colModel: [{ name: "idCountryTranslate", index: "IdCountryTranslate", editable: true, hidden: true },
{ name: "countryTranslateCode", index: "countryTranslateCode", editable: true, hidden: true, edittype: "text", editoptions: { defaultValue: countryCode} },
{ name: "language", index: "Language", label: "Язык", width: 100, editable: true, edittype: "select", editoptions: { value: "en:en;ru:ru;fr:fr;de:de" }, editrules: { required: true} },
{ name: "countryTranslateTitle", index: "countryTranslateTitle", label: "Название", width: 180, editable: true, editrules: { required: true}}],
rowNum: 5,
pager: pagerId,
sortname: 'language',
sortorder: "asc",
viewrecords: true,
gridview: true,
height: '100%'
});
//SUB GRID NAVIGATION PANEL
jQuery("#" + subgridTableId).jqGrid('navGrid', "#" + pagerId,
{ edit: true, add: true, del: true, search: false, refresh: false },
{mtype: "POST", closeAfterEdit: true, reloadAfterSubmit: true }, //edit parameters
{mtype: "POST", closeAfterAdd: true, reloadAfterSubmit: true }, //add parameters
{mtype: "POST", reloadAfterSubmit: true, serializeDelData: function (postdata) {
var rowdata = $("#" + subgridTableId).getRowData(postdata.id);
return { oper: postdata.oper, idCountryTranslate: rowdata.idCountryTranslate };
}
}, //delete parameters
{}//search parameteres
);
}
});
//MAIN GRID NAVIGATION PANEL
jQuery("#list").jqGrid('navGrid', "#pager",
{ edit: true, add: true, del: true, search: false, refresh: true },
{ mtype: "POST", closeAfterEdit: true, reloadAfterSubmit: true }, //edit parameters
{mtype: "POST", closeAfterAdd: true, reloadAfterSubmit: true }, //add parameters
{mtype: "POST", reloadAfterSubmit: true, serializeDelData: function (postdata) {
var rowdata = $("#list").getRowData(postdata.id);
return { oper: postdata.oper, idCountry: rowdata.idCountry };
}
}, //delete parameters
{}//search parameteres
);
});
</script>
<div style="margin:10px auto auto auto;width:100%;height:100%;">
<table id="list">
<tr>
<td/>
</tr>
</table>
<div id="pager"></div>
I use jqGrid plugin. There are grid and sub grid turned on. When I click second time to edit row from main grid then fields populates by wrong value.
Detailed steps to reproduce:
- Click edit row (main grid row)
- Edit form populated correctly, ok (see first screen)
- Click 'Cancel' button
- Click edit row again
- Edit form populated wrong (see second screen)
Here is my code:
$(function () {
$("#list").jqGrid({
url: 'Country/CountryListPaged',
editurl: "Country/AddEditDeleteCountry",
datatype: "json",
mtype: 'POST',
colModel: [
{ name: 'idCountry', index: 'idCountry', label: 'Id', width: 100, editable:true, hidden:true },
{ name: 'code', index: 'code', label: 'Код', width: 200, align:'center', editable: true, edittype:'text', editrules:{ required:true} },
{ name: 'title', index: 'title', label: 'Название', width: 300, align: 'center', editable: true, edittype: 'text', editrules: { required: true} }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20],
sortname: 'Title',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Список стран',
height: 'auto',
autowidth: true,
scrollOffset: 0,
hidegrid: false,
subGrid: true,
subGridRowExpanded: function (subgridId, rowId) {
var subgridTableId, pagerId;
subgridTableId = subgridId + "_t";
pagerId = "p_" + subgridTableId;
var tmp = $("#list").getRowData(rowId);
var idCountry = tmp.idCountry;
var countryCode = tmp.code;
$("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table><div id='" + pagerId + "' class='scroll'></div>");
jQuery("#" + subgridTableId).jqGrid({
url: "Country/CountryTranslateVariantsList?idCountry=" + idCountry + "&countryCode=" + countryCode,
editurl: "Country/AddEditDeleteCountryTranslateVariant",
mtype: "POST",
datatype: "json",
colModel: [{ name: "idCountryTranslate", index: "IdCountryTranslate", editable: true, hidden: true },
{ name: "countryTranslateCode", index: "countryTranslateCode", editable: true, hidden: true, edittype: "text", editoptions: { defaultValue: countryCode} },
{ name: "language", index: "Language", label: "Язык", width: 100, editable: true, edittype: "select", editoptions: { value: "en:en;ru:ru;fr:fr;de:de" }, editrules: { required: true} },
{ name: "countryTranslateTitle", index: "countryTranslateTitle", label: "Название", width: 180, editable: true, editrules: { required: true}}],
rowNum: 5,
pager: pagerId,
sortname: 'language',
sortorder: "asc",
viewrecords: true,
gridview: true,
height: '100%'
});
//SUB GRID NAVIGATION PANEL
jQuery("#" + subgridTableId).jqGrid('navGrid', "#" + pagerId,
{ edit: true, add: true, del: true, search: false, refresh: false },
{mtype: "POST", closeAfterEdit: true, reloadAfterSubmit: true }, //edit parameters
{mtype: "POST", closeAfterAdd: true, reloadAfterSubmit: true }, //add parameters
{mtype: "POST", reloadAfterSubmit: true, serializeDelData: function (postdata) {
var rowdata = $("#" + subgridTableId).getRowData(postdata.id);
return { oper: postdata.oper, idCountryTranslate: rowdata.idCountryTranslate };
}
}, //delete parameters
{}//search parameteres
);
}
});
//MAIN GRID NAVIGATION PANEL
jQuery("#list").jqGrid('navGrid', "#pager",
{ edit: true, add: true, del: true, search: false, refresh: true },
{ mtype: "POST", closeAfterEdit: true, reloadAfterSubmit: true }, //edit parameters
{mtype: "POST", closeAfterAdd: true, reloadAfterSubmit: true }, //add parameters
{mtype: "POST", reloadAfterSubmit: true, serializeDelData: function (postdata) {
var rowdata = $("#list").getRowData(postdata.id);
return { oper: postdata.oper, idCountry: rowdata.idCountry };
}
}, //delete parameters
{}//search parameteres
);
});
</script>
<div style="margin:10px auto auto auto;width:100%;height:100%;">
<table id="list">
<tr>
<td/>
</tr>
</table>
<div id="pager"></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了原因。包含“grid.subgrid.js”文件并导致问题。奥列格,谢谢您的回复。
I found the reason. "grid.subgrid.js" file was included and it caused problem. Oleg, thank you for response.