jqgrid, how to pass data when adding row using add navigator button

前端 未结 1 1826
长情又很酷
长情又很酷 2021-01-16 10:56

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

I tried code below to pass _dokdata with form values but _dokdata is no

相关标签:
1条回答
  • 2021-01-16 11:32

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

    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());
    }
    

    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.

    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.

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

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

    to

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

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

    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;
    }
    

    to for example the following

    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;
    }
    

    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;
    }
    

    can be changed to

    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;
    }
    

    and the line 304

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

    can be changed to

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

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

    0 讨论(0)
提交回复
热议问题