为什么其他数据无法从jqGrid发送到服务器方法使用editData

时间:2018-06-17 11:46:14

标签: jquery jqgrid

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

根据我的在线搜索,只需将其添加到编辑navGrid的代码块中的editData属性,即可将其他数据发送到服务器方法。下面是我的navGrid代码片段。

    .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)

1 个答案:

答案 0 :(得分:0)

您需要在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 }

);