Table of Contents

Cell Editing

Cell editing provides the frontend user with functionality to change the contents of one single cell from a row and then the developer has the abbility to handle the changed data by AJAX or in a jqGrid cell edit event (see below).

Cell Editing supports key navigation and editing individual cells, with the following behaviour:

Installation

In order to use this module you should mark the Cell editing and Common when you download the grid. For more information refer to Download.

For Developers of the JQuery plugin itself they can use the grid.celledit.js file in the src directory.

The properties, events and methods used in cell editing are a sub-set of those of the parent grid, and described below

Properties

These properties are specific for cell editing and should be set in grid options

PropertyTypeDescriptionDefault
cellEditbooleanEnables (disables) cell editing. When this option is set to true, onSelectRow event can not be used, and hovering is disabled (when mouseover on the rows).false
cellsubmitstringDetermines where the contents of the cell are saved - can have two values: 'remote' or 'clientArray'.
If remote the content of the cell if anything is changed is immediately saved to the server using the cellurl property, via ajax. The rowid and the cell content are added to the url by default. If you have the “mtype” setting set to post, the key value pears will be send as post variables. For example, if we save the cell named mycell,{id: rowid, mycell: cellvalue} is added to the url.
If cellsubmit is 'clientArray', no ajax request is made and the content of the changed cell can be obtained via the method getChangedCells or thru a event.
remote
cellurlstringthe url where the cell is to be saved. You need to set this only when you use cellsubmit as 'remote'.null
ajaxCellOptionsobjectThis option allow to set global ajax settings for the cell editiing when we save the data to the server. Note that with this option is possible to overwrite all current ajax setting in the save request including the complete event.empty object

Examples

When using the 'remote' setting you could add these lines to your grid configuration:

{
	'cellEdit' : true,
	'cellsubmit' : 'remote',
	'cellurl' : '/url/to/handling/the/changed/cell/value'
}

When your are using 'clientArray' as cellsubmit setting, only these settings are important:

{
	'cellEdit' : true,
	'cellsubmit' : 'remote'
}

Events

These events are related to cell editing and should be used in grid options.

Many of the following events use the parameters defined here:

EventParametersDescription
afterEditCellrowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event fires after the edited cell is edited - i.e. after the element is inserted into the DOM
afterRestoreCellrowid, value, iRow, iColapplies only to a cell that is editable; this event fires after calling the method restoreCell or the user press ESC leaving the changes
afterSaveCellrowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event fires after the cell has been successfully saved. This is the ideal place to change other content.
afterSubmitCellserverresponse, rowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event Fires after the cell and other data is posted to the server Should return array of type [success(boolean),message] when return [true,“”] all is ok and the cellcontent is saved [false,“Error message”] then a dialog appears with the “Error message” and the cell content is not saved. servereresponse is the response from the server. To use this we should use serverresponse.responseText to obtain the text message from the server.
beforeEditCellrowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event fires before editing the cell.
beforeSaveCellrowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event fires before validation of values if any. This event can return the new value which value can replace the edited one
beforeSaveCell : function(rowid,celname,value,iRow,iCol) {
if( some_condition )
{ return “new value”; }
}
The value will be replaced with “new value”
beforeSubmitCellrowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event fires before submit the cell content to the server (valid only if cellsubmit : 'remote'). Can return new array that will be posted to the server.
beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {
if( some_condition ) {
return {name1:value1,name2:value2}
}
else
{ return {} }
}
The returned array will be added to the cellurl posted data.
errorCellserverresponse, statusfires if there is a server error; servereresponse is the response from the server. To use this we should apply serverresponse.responseText to obtain the text message from the server. status is the status of the error. If not set a modal dialog apper.
formatCellrowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event allows formatting the cell content before editing, and returns the formatted value
onSelectCellrowid, celname, value, iRow, iColapplies only to cells that are not editable; fires after the cell is selected
serializeCellDatapostdataIf set this event can serialize the data passed to the ajax request when we save a cell. The function should return the serialized data. This event can be used when a custom data should be passed to the server - e.g - JSON string, XML string and etc. To this event is passed the data which will be posted to the server

Event calling stack

Depending on your cellSubmit setting set to 'remote' or 'clientArray' the following events will be fired in the following order:

cellSubmit setting 'remote'

  1. formatCell (rowid, cellname, value, iRow, iCol) : You can change the cell value here which will be used in the edit mode
  2. beforeEditCell (rowid, cellname, value, iRow, iCol) : Just before the cell jumps into edit mode this event is fired
  3. afterEditCell (rowid, cellname, value, iRow, iCol) : Just after the input element is created this event will be fired
  4. beforeSaveCell (rowid, cellname, value, iRow, iCol) : Fires before the cell is saved, you can save the value here which is send to the server.
  5. beforeSubmitCell (rowid, cellname, value, iRow, iCol) : Fires before value will be send to the server, you can add extra parameters here to the request by returning an array
  6. afterSubmitCell (serverresponse, rowid, cellname, value, iRow, iCol) : Fires only if saving cell is succesful, you can return a error message here that causes a dialog with the message
  7. afterSaveCell (rowid, cellname, value, iRow, iCol) : Fires when the value of the cell is saved
  8. errorCell (serverresponse, status) : Fires when a server error is occured (like: 403, 404, 500, etc)
  9. onSelectCell (rowid, celname, value, iRow, iCol) : Fires when a cell is not editable

cellSubmit setting 'clientArray'

  1. formatCell (rowid, cellname, value, iRow, iCol) : You can change the cell value here which will be used in the edit mode
  2. beforeEditCell (rowid, cellname, value, iRow, iCol) : Just before the cell jumps into edit mode this event is fired
  3. afterEditCell (rowid, cellname, value, iRow, iCol) : Just after the input element is created this event will be fired
  4. beforeSaveCell (rowid, cellname, value, iRow, iCol) : Fires before the cell is saved by user
  5. beforeSubmitCell (rowid, cellname, value, iRow, iCol) : You can save the value somewhere here
  6. afterSaveCell (rowid, cellname, value, iRow, iCol) : Fires when the value of the cell is succesfully saved by beforeSubmitCell
  7. onSelectCell (rowid, celname, value, iRow, iCol) : Fires when a cell is not editable

Methods

All of the methods below should be applied to the jqGrid object and all of them return the same object.

MethodParametersDescription
editCelliRow, iCol, editedit a cell with the row index iRow( do not mix with rowid) in index column iCol. If the edit is set to false the cell is just selected and not edited. If set to true the cell is selected and edited.
getChangedCellsmethodReturns an array of the changed cells depending on method (string, default 'all'). When 'all' this method returns all the changed rows; when 'dirty' returns only the changed cells with the id of the row
restoreCelliRow, iColrestores the edited content of cell with the row index iRow( do not mix with rowid) in index column iCol
saveCelliRow, iColsaves the cell with the row index iRow( do not mix with rowid) in index column iCol

Notes

How is the data organized

When the cell is edited and the input elements is created we set the following rules:

What is posted to the server?

When the data is posted to the server we construct object {} that contain: