For inline editing, we have three additional methods (of the Grid API) available:
- editRow
- saveRow
- restoreRow
These methods can be called, of course, only on an already-constructed grid, from a button click or from an event of the grid itself:
onSelectRow: function(id){
if(id && id!==lastSel){
jQuery('#tbleditable').restoreRow(lastSel);
lastSel=id;
}
jQuery('#tbleditable').editRow(id, true);
},
In this example, if another was row being edited and has not yet been saved, the original data will be restored and the row "closed" before "opening" the currently-selected row for editing (where lastSel was previously defined as a var).
editRow
Calling convention:
editRow(rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc, onerrorfunc)
where
- rowid: the id of the row to edit
- keys: when set to true we can use [Enter] key to save the row and [Esc] to cancel editing.
- oneditfunc: fires after successfully accessing the row for editing, prior to allowing user access to the input fields. The row's id is passed as a parameter to this function.
If
keys is
true, then the remaining settings --
succesfunc,
url,
extraparam,
aftersavefunc and
onerrorfunc -- are passed as parameters to the
saveRow method when the [Enter] key is pressed (
saveRow does not need to be defined as jqGrid calls it automatically). For more information see
saveRow method below.
When this method is called on particular row, jqGrid reads the data for the editable fields and constructs the appropriate elements defined in edittype and editoptions.
saveRow
Calling convention:
saveRow (rowid, succesfunc, url, extraparam, aftersavefunc, onerrorfunc)
where
- rowid: the id of the row to save
- succesfunc: if defined, this function is called immediately after the request is successful. To this function is passed the data returned from the server. Depending on the data from server this function should return true or false.
- url: if defined, this parameter replaces the editurl parameter from options array. If set to clientArray, the data is not posted to the server but is saved only to the grid (presumably for later manual saving).
- extraparam: an array of type name: value. When set these values are posted along with the other values to the server.
- aftersavefunc: if defined, this function is called after the data is saved to the server. Parameters passed to this function are the rowid and the result from the request.
- onerrorfunc: if defined, this function is called after the data is saved to the server. Parameters passed to this function are the rowid and the result from the request.
Except when url (or editurl) is 'clientArray', when this method is called, the data from the particular row is POSTED to the server in format name: value, where the name is a name from colModel and the value is the new value. jqGrid also adds, to the posted data, the pair id: rowid. For example,
jQuery("#grid_id").saveRow("rowid", false);
will save the data to the grid and to the server, while
jQuery("#grid_id").saveRow("rowid", false, 'clientArray');
will save the data to the grid without an ajax call to the server.
restoreRow
Calling convention:
restoreRow(rowid)
where
- rowid is the row to restore
This method restores the data to original values before the editing of the row.