1

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 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());
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
Andrus
  • 26,339
  • 60
  • 204
  • 378
  • I fixed position of the `` before the code. Now you see that the code will be formatted with colors specific for JavaScript. If you would use additional jquery or javascript tags you will not need to add `` to have good formatted (with colors) code. – Oleg Dec 18 '11 at 21:23

1 Answers1

4

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thank you. I tried but enter key does not end inline add. How to save added row pressing Enter ? – Andrus Dec 18 '11 at 16:25
  • @Andrus: It was first a small typing error: I used `key: true` instead of `keys: true`. More important is a bug which I describe in the "UPDATED" part of my answer together with the corresponding bug fix. – Oleg Dec 18 '11 at 18:03
  • In IE9 I pressed Add button in latest demo, filled client name and pressed enter. Save and cancel buttons in toolbar are still active. How to disable them after successful add on enter? if error occurs on add, added row disappears. How to keep inline add mode on add error to allow user to currect data? Also createContexMenuFromNavigatorButtons is undefined – Andrus Dec 18 '11 at 18:52
  • @Andrus: I hope that I fixed the bug at the end. See my updated answer. One more remark. Please include `jquery` or `javascript` tag in the question to have better formatting of the code. Currently I had to include [](http://meta.stackexchange.com/a/81970/147495) comment in every fragment of the code. – Oleg Dec 18 '11 at 20:11
  • Thank you. Where to download correct jquery js file? I need to apply also 2 other bugfixes to it (deleting and sorting) to use it. I added language tag to question but havent noticed differecne. – Andrus Dec 18 '11 at 20:33
  • @Andrus: You should modify the code of `jquery.jqGrid.src.js` yourself. You need just search for the text `o = $.extend($.jgrid.inlineEdit, settings, args[0]);`. [The file](http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.0/js/jquery.jqGrid.src-multiselect1.js) which I used for the demo used two fixes. You can compare if with original file for example with respect of WinDiff.exe from the Windows SDK Tools included in Visual Studio. All other bug fixes which you need you have to apply yourself. – Oleg Dec 18 '11 at 21:29
  • 1
    @Andrus: I posted [the following comment](https://github.com/tonytomov/jqGrid/commit/df5193e9c278247afb4d634b204f66242aedd55f#commitcomment-804700) to Tony about the described problem. – Oleg Dec 18 '11 at 21:38
  • 1
    @Andrus: How you can read [here](https://github.com/tonytomov/jqGrid/commit/df5193e9c278247afb4d634b204f66242aedd55f#commitcomment-805226) my suggestions are already in the main code of jqGrid and how Tony wrote it will be published new fixed version probably today. – Oleg Dec 19 '11 at 07:29
  • I tried code from github but problem persists. How to fix it ? Also bugs on delete (fix provided in http://www.trirand.com/blog/?page_id=393/bugs/exception-after-successful-delete-in-complete-event-handler/ ) and on sorting clicking in column header are not fixed in git. – Andrus Dec 20 '11 at 09:33
  • I added commit request for delete issue. One line fix but after editing with visual studio formatting also was changed https://github.com/kobruleht/jqGrid/commit/3bbb6d8f0285aec0cb45fd7b2e98b6cdccddc645 – Andrus Dec 20 '11 at 11:22
  • @Andrus: You can just press **Ctrl-Z** (Undo) after the Visual Studio changes the formatting of the file. It will undo the *reformatting* of the code, but your changes will be hold. Alternatively you can change the settings of Visual Studio. Open menu "Tools" / "Options...", choose "Text Editor"/"JScript"/"Formatting" in the left tree control. Then uncheck all checkboxes in the "Automatic formatting" group. You can edit the file in any other text editor like [Notepad ++](http://notepad-plus-plus.org/) for example. **I think that "delete" bug has no relation with your current question.** – Oleg Dec 20 '11 at 12:24
  • 1
    @Andrus: See "UPDATED 3" part. – Oleg Dec 20 '11 at 13:53
  • Thank you. I tried `jquery.jqGrid.src-delete.js` from last demo. It does not accept settings from Site.Master specified like `jQuery.extend(jQuery.jgrid.defaults, { mtype: 'POST', ...` – Andrus Dec 20 '11 at 16:49
  • 1
    @Andrus: You just spend my time. I tried to set `jQuery.jgrid.defaults` and how you can see from [the demo](http://www.ok-soft-gmbh.com/jqGrid/SendDataFromInlineNav2.htm) it works without any problem. You can use WinDiff.exe to compare `jquery.jqGrid.src-delete.js` with `jquery.jqGrid.src.js` and see exactly that I made only the changes which I described. If any problem exist it's not because of my changes. Moreover I write you before that all the discussion about problems in "Delete" have nothing common with your question about `extraparam` which I answered. – Oleg Dec 20 '11 at 17:46
  • Thank you very much. I'm sorry about that. I didnt include jqgrid locale file. This blocks jqgrid defaults without any error. extra parameters are passed OK now. In my testcase ending inline add keeps toolbar save/cancel buttons active but this may be issue in my code. I posted reply about delete issue in trirand forum message. Sorry again wasting your time. – Andrus Dec 23 '11 at 13:35
  • @Oleg Sorry But I can not Ask Question so in jqgrid rownumber:true property same thing i want in column in inline nav Grid. – Ashish Mehta May 11 '13 at 13:00
  • @Oleg So i am use setCell in dataInit function but it is not working – Ashish Mehta May 11 '13 at 13:00
  • @AshuMehta: Sorry, but I don't understand what you exactly do and what is your problem. Why you can't ask new question? In new question you could include the code which you currently use and describe your problem in details. I can help you only if I understand your problem. So your should just explain all in your new question. – Oleg May 11 '13 at 14:16
  • @Oleg I can not Ask New Question – Ashish Mehta May 12 '13 at 05:58
  • @Oleg I am use Inline nav.and In jqGrid rownumber property is available which is give rownumber a side of row. ok so I have column "TID" i want this Column Value Like rownumber So How to do? Please Help – Ashish Mehta May 12 '13 at 06:07
  • @AshuMehta: I don't know some restriction so that one can't ask new questions. If you need access to some column then it's mostly important the context in which you do this. Access of editing row is mostly easy by `id` of the cell. For example in case of inline editing it could be `$("#123_TID").val()` where `123` is the rowid. – Oleg May 12 '13 at 10:22