jqgrid,如何使用添加导航器按钮添加行时传递数据 [英] jqgrid, how to pass data when adding row using add navigator button

查看:193
本文介绍了jqgrid,如何使用添加导航器按钮添加行时传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用添加导航器"按钮添加了行,如何传递附加的POST键来添加控制器?

How to pass additional POST key to add controller if row is added using Add navigator button?

我尝试了下面的代码以表单格式传递_dokdata,但是_dokdata没有传递给控制器 服务器.

I tried code below to pass _dokdata with form values but _dokdata is not passed to controller in server.

$("#grid").jqGrid('inlineNav', '#grid_toppager', {
   addParams: {
    useDefValues : true,
    useFormatter : false,
    addRowParams : {
        extraparam : { _dokdata : FormData },
       editData: { _dokdata: FormData },
       },
    editData: { _dokdata: FormData },
    extraparam : { _dokdata : FormData },
   },

   add: true,
   edit: false,
   save: true,
   cancel: true,
   editParams : {}
   }); 

function FormData() {
    return JSON.stringify($("#_form").serializeArray());
}

推荐答案

似乎您描述的问题是代码中的小错误和jqGrid代码中的错误的混合体(请参阅以这个地方).

It seems that the problem which you describe is the mix from small error in your code and the bug in the code of jqGrid (see lines starting with the place).

您的代码中的问题是您没有像对addParams那样正确地设置editParams.正确的用法应该是:

The problem in your code is that you don't set editParams correctly like you do as for addParams. The correct usage should be:

$("#grid").jqGrid('inlineNav', '#grid_toppager', {
    addParams: {
        useDefValues: true,
        addRowParams: {
            keys: true,
            extraparam: { _dokdata: FormData }
        }
    },
    editParams: {
        extraparam: { _dokdata: FormData }
    },
    add: true,
    edit: false,
    save: true,
    cancel: true
}); 

function FormData() {
    return JSON.stringify($("#_form").serializeArray());
}

在我看来,当前版本的jqGrid代码中存在的问题是jqGrid在 仅保存按钮(请参见此处)使用editParams.extraparam的设置代替使用addParams.addRowParams.extraparam之类的东西.我在inlineNavaddParams.addRowParams参数中添加了keys: true选项.因此,您将看到,如果用户通过按 Enter 保存更改,并且用户保存时将使用editParams.extraparam,则jqGrid的当前实现(v 4.3.0)将使用addParams.addRowParams.extraparam导航按钮的保存"按钮排成一行.

The problem in the current version of the code of jqGrid is in my opinion that jqGrid use in the Save button (see here) only the setting of editParams.extraparam are used instead of the usage of something like addParams.addRowParams.extraparam. I added keys: true option in the addParams.addRowParams parameters of inlineNav. So you will see that the current implementation (v 4.3.0) of the jqGrid will use addParams.addRowParams.extraparam if the user will save the changes by pressing of Enter and will use editParams.extraparam in case of saving the row by "Save" button of the navigator buttons.

已更新:我测试了代码,并在jqGrid 4.3.0版中发现了另一个错误.我在

UPDATED: I tested the code and found one more bug in jqGrid v. 4.3.0. I suggested in the feature request to introduce $.jgrid.inlineEdit setting which can be used like other very practical setting $.jgrid.edit but in case of inline and not form editing. The feature request is implemented in jqGrid 4.3.0, but the implementation contains a bug.

要修复该错误,应替换 33 117 304 来自

To fix the bug one should replace the lines 33, 117 and 304 from

o = $.extend($.jgrid.inlineEdit, settings, args[0]);

o = $.extend(true, {}, settings, $.jgrid.inlineEdit, args[0]);

如何从演示中查看,错误修复.

How you can see from the demo, all work correctly after the bug fixing.

更新2 :上面的修复与修复仍然不正确.要修复该错误,必须在代码中进行更多更改.例如,行 32-36 (在editRow内部)可以更改为

UPDATED 2: The above fix is identical to the fix which is still incorrect. To fix the bug one have to make more changes in the code. For example the lines 32-36 (inside of editRow) can be changed from

if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
    o = $.extend($.jgrid.inlineEdit, settings, args[0]);
} else {
    o = settings;
}

例如以下

if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
    settings.keys = false; // keys is args[0] and it's an object
    o = $.extend(true, {}, settings, $.jgrid.inlineEdit, args[0]);
} else {
    o = settings;
}

以相同的方式 116-120 (在saveRow内部)

In the same way the lines 116-120 (inside of saveRow)

if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
    o = $.extend($.jgrid.inlineEdit, settings, args[0]);
} else {
    o = settings;
}

可以更改为

if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
    settings.successfunc = null; // successfunc is args[0] and it's an object
    o = $.extend(true, {}, settings, $.jgrid.inlineEdit, args[0]);
} else {
    o = settings;
}

和以下行 304

o = $.extend($.jgrid.inlineEdit, settings, args[0]);

可以更改为

o = $.extend(true, {afterrestorefunc: null}, $.jgrid.inlineEdit, args[0]);

更新3 :我发布了此处查看相同的演示.

UPDATED 3: I posted my suggestion to trirand about the "Delete" problem. See the same demo which uses the fix here.

这篇关于jqgrid,如何使用添加导航器按钮添加行时传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆