【问题标题】:Why Does Additional Data Fail To Be Sent To Server Method From jqGrid Using editData为什么使用editData从jqGrid向服务器方法发送附加数据失败
【发布时间】:2018-06-17 11:46:14
【问题描述】:

我正在尝试使用 jqGrid editData 属性向服务器上的方法发送附加数据,但它不起作用。基本上,当我选择我的 jqGrid 行然后单击作为垃圾桶图标的删除按钮时,我想将一些数据发送到服务器上的方法。

根据我的在线搜索,可以将附加数据发送到服务器方法,只需将它们添加到 navGrid 的 Edit 代码块中的 editData 属性即可。下面是我的 navGrid 代码的 sn-p。

    .navGrid('#jqControls', { add: false, edit: true, del: true, search: true, refresh: true },

    //setting for add
    {},
    //Setting for edit
    {
        zIndex: 100,
        closeOnEscape: true,
        closeAfterEdit: true,
        recreateForm: true,
        width: '100%',
        height: '100%',
        // sending extra parameter on click of submit after edit.
        // these values will be in signature of EditProductsDetails method in formcontroller as status and gridRowData. 
        editData: {
            status: "Active",
            gridRowData:function() {
                var cLIds = "[{";
                var i, selRowIds = $("#jqGrid").jqGrid("getGridParam", "selarrrow"), n, rowData;

                for (i = 0, n = selRowIds.length; i < n; i++) {
                    rowData = myGrid.jqGrid("getLocalRow", selRowIds[i]);
                    if (i < n - 1) {
                        prdlIds += "{'ProductlineId': " + rowData.ProductlineId + "}, ";
                    } else {
                        prdlIds += "{'ProductlineId': " + rowData.ProductlineId + "}]";
                    }
                }
                var productlineIds = JSON.stringyfy(prdlIds);
                return productlineIds;
            }
        }           
    },       

    //setting for delete
    {
        zIndex: 100,
        closeOnEscape: true,
        closeAfterDelete: true,
        recreateForm: true
    }, 
    //search setting
    { multipleSearch: true },
    { closeOnEscape: true }

    );

以下是服务器方法签名:

    EditProductsDetails(string oper, Products prod, string status, string gridRowData)

【问题讨论】:

  • 使用哪个 jqGrid - Guriddo jqGrid、免费 jqGrid 或 jqGrid these docs
  • 我正在使用 Guriddo jqGrid,我对它真的很陌生。我正在处理其他人编写的现有代码。例如,当单击垃圾桶图标时,我仍在试图弄清楚数据是如何传递到后端的,并且既没有使用数据也没有使用发布数据来清楚地说明网格中的哪些数据被发送回 editurl。

标签: jquery jqgrid


【解决方案1】:

您需要在 delData 中添加此代码,而不是在编辑数据中。不需要序列化 ​​json 数据,因为你已经有了字符串:

.navGrid('#jqControls', { add: false, edit: true, del: true, search: true, refresh: true },

//setting for add
{},
//Setting for edit
{
    zIndex: 100,
    closeOnEscape: true,
    closeAfterEdit: true,
    recreateForm: true,
    width: '100%',
    height: '100%'
},       

//setting for delete
{
    zIndex: 100,
    closeOnEscape: true,
    closeAfterDelete: true,
    recreateForm: true,
    // sending extra parameter on click of submit after edit.
    // these values will be in signature of EditProductsDetails method in formcontroller as status and gridRowData. 
    delData: {
        status: "Active",
        gridRowData:function() {
            var prdlIds = "[{";
            var i, selRowIds = $("#jqGrid").jqGrid("getGridParam", "selarrrow"), n, rowData;

            for (i = 0, n = selRowIds.length; i < n; i++) {
                rowData = myGrid.jqGrid("getLocalRow", selRowIds[i]);
                if (i < n - 1) {
                    prdlIds += "{'ProductlineId': " + rowData.ProductlineId + "}, ";
                } else {
                    prdlIds += "{'ProductlineId': " + rowData.ProductlineId + "}]";
                }
            }
            // no need to serialize prdlIds is already a string
            return prdlIds;
        }
    }           

}, 
//search setting
{ multipleSearch: true },
{ closeOnEscape: true }

);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    相关资源
    最近更新 更多