tempid
tempid

Reputation: 8198

jqgrid callback function after save

I'm using the following snippet to call manually call the save function on the grid. I'm using inline editing. The save function needs to return a custom object. How do I access the return value? Is there a callback function? Does the successfunc only return true/false?

jQuery("#grid_id").jqGrid('saveRow',rowid, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);

Upvotes: 0

Views: 10386

Answers (1)

Oleg
Oleg

Reputation: 221997

If you use saveRow to save the local data you can just set the value of some external variable (the variable defined in the outer scope) inside of your mySaveFunction. It's important only to understand, that you have to use aftersavefunc parameter of editRow (or saveRow) instead of succesfunc parameter. It's typical misunderstanding, but the succesfunc callback will be called only in case of saving the data on the server. The succesfunc callback will be not called in case of 'clientArray'. I recommend you to use "object" form of the editRow usage:

var someRetValue;
jQuery("#grid_id").jqGrid('saveRow', rowid,
{
    url: 'clientArray'
    aftersavefunc: function (id, response, options) {
        someRetValue = response; // set someRetValue to any value
    }
});

On the other side you can consider to use callback functions as the parameter of your own "Save" function. If the "Save" will have afterSaveFunc parameter you will not need to use any return value of the "Save" function. You should just build your JavaScript script to work asynchronous instead of the classical synchronous sequential execution order.

Upvotes: 2

Related Questions