0

After following the solution in a previous post, I have found that the jqGrid refresh after add/edit with the inlineNav using the successfunc does not work if extraparams is present.

Here's my code:

var editOptions = {    
keys: true,
successfunc: function () {
    alert('success');
    var $self = $(this);
    setTimeout(function () {
        alert('refreshing');
        $self.setGridParam({ datatype: 'json' });
        $self.trigger("reloadGrid");
    }, 500);
} 


 .jqGrid('inlineNav', {
                addParams: {
                    useDefValues: true,
                    addRowParams: 
                    {
                        editOptions,
                        extraparam: {
                                userId: function () {
                                    return currentUserId;
                                },
                                companyId: function () {
                                    return currentCompanyId;
                                }
                        }
                    }                        
                },
                editParams: {
                    editOptions
                }

I have tried different combinations of where the editOptions is placed, but no luck.

Community
  • 1
  • 1
Jerry P
  • 49
  • 6

2 Answers2

2

You placed extraparam in the wrong place. It should be the property of editOptions.

UPDATED:

var reloadGridFunc = function () {
    alert('success');
    var $self = $(this);
    setTimeout(function () {
        alert('refreshing');
        $self.setGridParam({ datatype: 'json' });
        $self.trigger("reloadGrid");
    }, 500);
};


.jqGrid('inlineNav', {
            addParams: {
                useDefValues: true,
                addRowParams: {
                    // here are editOption used for Add
                    keys: true,
                    successfunc: reloadGridFunc,
                    extraparam: {
                            userId: function () {
                                return currentUserId;
                            },
                            companyId: function () {
                                return currentCompanyId;
                            }
                    }
                }                        
            },
            editParams: {
                // here are editOption used for Edit
                keys: true,
                successfunc: reloadGridFunc
            }
        });
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • It was my understanding that I needed to put any add parameters into the add param section. I only need these extra parameters for the add function only. – Jerry P Jul 15 '16 at 12:36
  • @JerryP: Yes, but `addParams: { addRowParams: {editOptions, extraparam: {...}}}` which you use is **wrong**. `addParams: { addRowParams: editOptions}` would be correct and `addParams: { addRowParams: {keys: true, extraparam: {...}, successfunc: function () {...}}}` would be correct too. The value of `addParams` should be **object** like parameters of `addRow` function (see [here](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#addrow)). The object can have `addRowParams` property. The value of `addRowParams` property should be **object** with the options of `editRow`. – Oleg Jul 15 '16 at 13:56
  • @JerryP: The options of `editRow` are describe [here](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow). The syntax `{ editOptions, extraparam: {...}}` which you use is already wrong. What is `editOptions` here? The correct syntax should be `{property1Name: property1Value, property2Name: property2Value, ...}`. – Oleg Jul 15 '16 at 14:01
  • the editOptions is to add the refresh to both the add and edit of the inline editting. Its just a var that points to the function at the top of code I submitted. Does that answer your question and/or make sense? – Jerry P Jul 15 '16 at 15:39
  • @JerryP: Look at the **UPDATED** part, where I included the code example, which you can use. – Oleg Jul 15 '16 at 16:06
0

Ok - I found what I was doing wrong. It was actually in both parts of my code above. First, I changed:

function successFunc() {   
var $self = $(this);
setTimeout(function () {        
    $self.setGridParam({ datatype: 'json' });
    $self.trigger("reloadGrid");
}, 500);}

I got rid of the var editOptions, which included the keys and successfunc parameters inside it. This apparently was conflicting with the successfunc call in the addParams part of the inlineNav method. So here's what the parameters section looks like now:

 .jqGrid('inlineNav', {
                addParams: {
                    addRowParams:
                    {
                        keys: true,
                        extraparam: 
                         { userId: currentUserId, 
                           companyId: currentCompanyId 
                        },
                        successfunc: successFunc
                    }
                },
                editParams: {
                    successfunc: successFunc
                }
            });

So now when I either add or edit an inline record, the refresh happens when the successfunc is called. Hope this helps someone else in the future. Thanks @Oleg for the initial help with this.

Jerry P
  • 49
  • 6