jqGrid 编辑表单预填了错误的值。 (第二次点击时)

发布于 2025-01-06 22:39:40 字数 5471 浏览 2 评论 0原文

我使用 jqGrid 插件。有网格和子网格打开。当我第二次单击以编辑主网格中的行时,字段会填充错误的值。 重现的详细步骤:

  1. 单击编辑行(主网格行)
  2. 编辑表单正确填充,确定(参见第一个屏幕)
  3. 单击“取消”按钮
  4. 再次单击编辑行
  5. 编辑表单填充错误(参见第二个屏幕)

这是我的代码:

$(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:

  1. Click edit row (main grid row)
  2. Edit form populated correctly, ok (see first screen)
  3. Click 'Cancel' button
  4. Click edit row again
  5. 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>

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩套路吗 2025-01-13 22:39:40

我找到了原因。包含“grid.subgrid.js”文件并导致问题。奥列格,谢谢您的回复。

I found the reason. "grid.subgrid.js" file was included and it caused problem. Oleg, thank you for response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文