Search code examples
javascriptjqueryasp.netasp.net-mvcjqgrid

JqGrid fires 'aftersavefunc' & 'successfunc' before 'saveRow'


I'm trying to reload the grid after saving a row to be able to get the Id of the row for logging purposes but somehow 'aftersavefunc' and 'successfunc' fires 'reloadGrid('#telephoneGrid')' before saving. It seems that 'aftersavefunc' and 'successfunc' is identical. Now I can't add nor edit any row.

    var lastSel;

    function onTelephoneSelect(id, status, e) {

        if ($(e.target).hasClass('edit')) {
            var editParameters = getEditParameters();
            if (id && id !== lastSel) {
                jQuery('#telephoneGrid').saveRow(lastSel);
            }
            jQuery("#telephoneGrid").jqGrid('editRow', id, editParameters);
            lastSel = id;
        }
    }

    function getEditParameters() {
        return {
            "keys": true,
            "oneditfunc": null,
            "successfunc": null,
            "url": '@Url.Action("SaveTelephoneEntry","TelephoneEntry")?customerId=' + $('#SelectCompany').val(),
            "extraparam": {},
            "aftersavefunc": reloadGrid('#telephoneGrid'),
            "errorfunc": null,
            "afterrestorefunc": null,
            "restoreAfterError": true,
            "mtype": "POST"
        }
    }

I'm pretty desperate now and couldn't figure out any working solution.

Could someone please assist me here or has already faced the same issue and figured out a working solution?

Many thanks in advance.


Solution

  • 'aftersavefunc' and 'successfunc' are callbacks but it appears you're trying to set the function directly, so they're getting called before you intend.

    Using the proper callback signature it should look something like this:

    "aftersavefunc": function (rowid, response, options) {
        reloadGrid('#telephoneGrid');
    },