jqueryjqgridjqgrid-formatter

How to define a 'before save' callback in jqGrid's 'action' formatter?


I'm using the built-in 'action' formatter to edit inline (row editing) and to delete.

The problem is that I want to validate via ajax (so, returning true field could be saved) but I couldn't add any 'before save' callback in the save statment.

Image with an example of the view.

The colModel I use to define the Actions col:

{name: 'Actions', formatter: 'actions',
                  editable: false,
                  search: false,
                  width: '50',
                  sortable: false,
                  resizable: false,
                  formatoptions:{
                      keys:true
                  }
}

Solution

  • In the list of parameters of the actions formatter you can define onError callback function (see the answer). It's important that the server returns some error status code in case of any kind errors during the saving of data. The validation of the data which will be send is one of the examples of such errors.

    UPDATED: The answer is very old. Inline editing supports beforeSaveRow since a long time (sine the version 4.5.3). Nevertheless the callback provide client side validation. The question was about server side validation via Ajax request to the server. In the case onError is still almost the only good way to do this. The server need just to set HTTP status code which corresponds HTTP error (>=400). Only if the server can't set HTTP error code one can use successfunc callbackalternatively, which correspondsonSuccessinformatter: "actions". The callback should return [false, "error description"] in case of validation error.