Search code examples
jqueryjqgridmvcjqgrid

Which event is fired after serializeRowData in jqGrid?


I have two jqGrids on a page. The idea is to display a confirmation dialog when a drop down value is updated and when the user presses enter to save the record both jqGrids get reloaded.

Here's my column model:

{
    key: false, name: 'InterestedValue', index: 'InterestedValue', editable: true,
    sortable: false, formatter: 'select', width: '120px', search: false,
    edittype: 'select',
    editoptions: {
        value: InterestedStatusList,
        //afterSaveCell: function (rowid, cellname, value, iRow, iCol) {
        //    alert("after savecell" + rowid + " cellname= " + cellname);
        //    //$(this).trigger('reloadGrid');
        //},
        successfunc: function (response) {
            alert("success");
            //FLAG = true;
            $(this).trigger('reloadGrid')
            return true;
        }

    }
},

And event,

serializeRowData: function (postdata) {
   var response = JSON.stringify(postdata);
   var s = '';
   $(postdata).each(function (index, data) {
       //s += '<option value="' + index + '">' + data + '</option>';
       $.each(data, function (k, v) {
           if(k=="InterestedValue")
            s += v;//'<option value="' + k + '">' + v + '</option>';
       });

   });
   //
   if (s == "2_1") {
       if (confirm('Are you sure you want to deactivate this record? ')) {
           // do things if OK
           return postdata;
       }
       else
           return false;
   }
   return postdata;
},

I am able to get the edit action method called with data after the serializeRowData event. But I can't figure out how to trigger the reload of the Grids after the update is done successfully. So please tell me which event gets fired after the serializeRowData. I tried the successfunc in the column as well, but this is fired as soon as the I click the row and it goes into Edit-mode.


Solution

  • Thanks for the details @Oleg.

    The serializeRowData method I posted earlier was able to put up the JavaScript confirmation dialog for the user before deactivation of the record. Here's how I managed to reload the jqGrids after the update was done on the server.

    I used the editRow

    $(gridId).jqGrid("editRow", 'kkk', true, '', '', '', '', reload)
    

    And in the reload method, I triggered the reloading of jqGrids as

    function reload(rowid, result) {
    var s = '';
    var o = false;
    var postdata = JSON.stringify(result);
    $(jQuery.parseJSON(postdata)).each(function (index, data) {
        $.each(data, function (k, v) {
            s += k + ":" + v + " --- ";
            if (k == "responseText")
            {
                if (v.indexOf("Deactivated") != -1)
                    o = true;
            }
            s += k + ":" + v + " --- ";
        });
    
    });
    
    if (o ==true) {
        //reload both grids
        $("#grid1").trigger("reloadGrid");
        $("#grid2").trigger("reloadGrid");
    }  }
    

    Hope that helps.