jQuery("#grid_id").jqGridMethod( parameter1,...parameterN )
Where:
IMPORTANT: Some 'get' and 'set' methods (e.g., getUrl()) supported up to version 3.1 have been removed in version 3.2 and replaced by more generic methods (e.g., getGridParam(url) or setGridParam({url:value}) ). See Replaced Methods for details.
Where a method is not designed to return a requested value, then what is returned is the jqGrid object and a set of such methods can be chained, e.g.,
jQuery("#grid_id").setGridParam({..}).hideCol("somecol").trigger("reloadGrid")
| Method | Parameters | Returns | Description |
|---|---|---|---|
| addJSONData | data | true on success, otherwise false | Populates a grid with the passed data (an array). Suppose we have data from a particular webservice (jsonresponse), then
var mygrid = jQuery("#"+grid_id)[0]; var myjsongrid = eval("("+jsonresponse.responseText+")"); mygrid.addJSONData(myjsongrid); myjsongrid = null; j sonresponse =null; will populate the data to the grid. And, of course, the data in myjsongrid can be manipulated before being passed to addJSONData. addJSONData is a privileged method. |
| addRowData | rowid, data, position (first, last, before, after - default last), srcrowid (source row, applies only when position is either before or after) | true on success, otherwise false | Inserts a new row with id = rowid containing the data in data (an array) at the position specified (first in the table, last in the table or before or after the row specified in srcrowid). The syntax of the data array is: {name1:value1,name2: value2…} where name is the name of the column as described in the colModel and the value is the value. |
| addXmlData | xmlresponse | true on success, otherwise false | Populates a grid with the passed data. Suppose we have data from a particular webservice (xmlresponse), then
var mygrid = jQuery("#"+grid_id)[0]; mygrid.addXmlData(xmlresponse.responseXML); will populate the data to the grid. And, of course, the data in xmlresponse can be manipulated before being passed to addXmlData. addXmlData is a privileged method. |
| clearGridData | none | jqGrid object | Clears the currently loaded data from grid |
| delRowData | rowid | true on success, otherwise false | Deletes the row with the id = rowid. This operation does not delete a data from the server. |
| FormToGrid | rowid, formid | jqGrid object | Reads data from a form (previously defined in html) identified by formid and loads data into the grid in row with rowid. If the names of both grid and form are the same the data from the form replaces the data in the grid. Note that all fields from grid can be replaced, including hidden. This is the opposite of GridToForm |
| getCell | rowid, iCol | the content of the cell | iCol can be either the column index or the name. |
| getDataIDs | none | array of the id's in the current grid view. Empty array if no data is available. | |
| getGridParam | name | the value of the requested parameter. | name is the name from options array. For a particular options, see below. If the name is not set the entry options are returned. |
| getRowData | rowid | array with data of the requested id = rowid. | The returned array is of type name:value, where the name is a name from colModel and the value is a actual value. Returns empty array if the row can not be found. |
| GridToForm | rowid, formid | jqGrid object | Reads data from the given rowid and fills the form (previously defined in html) identified by formid. If the names of both grid and form are the same the data from the grid replaces the data in the form. Note that all fields from grid can be used, including hidden. |
| hideCol | colname | jqGrid object | Hides a column with a given colname. If the colname is a string, only the specified column is hidden. If the colname is array of type ["name1","name2"] then the columns with names 'name1' and 'name2' will be hidden at the same time. The names in colname must be valid names from the colModel. The width of the grid is changed according to the following rules: if the grid currently has no horizontal scroll bar, the width of the grid is decreased by the width of the hidden column(s). If a scrollbar is visible, the width is adjusted which may or may not change the width of the grid. |
| resetSelection | none | jqGrid object | Resets (unselects) the selected row(s). Also works in multiselect mode. |
| setCaption | caption | jqGrid object | Sets a new caption of the grid. If the Caption layer was hidden, it is shown. |
| setCell | rowid, colname, data, class, properties | jqGrid object | This method can change the content of particular cell and can set class or style properties.
Where:
Example : setCell("10", "tax", '', {color:'red','text-align':'center'}',{title:'Sales Tax'}) will set the contents of the tax field in row 10 to red and centered and change the title to 'Sales Tax'. |
| setGridParam | object | jqGrid object | Sets a particular parameter. Note - for some parameters to take effect a trigger("reloadGrid") should be executed. Note that with this method we can override events like onSelectRow, etc.
Example: setGridParam({ url:"newurl", page:1, onSelectRow:function(id){/*here is the new code*/} }); The name (in the name:value pair) is the name from options array. For a particular options, see below. If the name is not set the entry options are returned. |
| setGridHeight | new_height | jqGrid object | Sets the new height of the grid dynamically. Note that the height is set only to the grid cells and not to the grid. <>new_height<> can be in pixels, percentage, or 'auto' |
| setGridWidth | new_width, shrink | jqGrid object | Sets a new width to the grid dynamically. The parameters are:
|
| setLabel | colname, newlabel, sattr | jqGrid object | Sets a new label in the header for the specified column; can also set attributes and classes (sattr). The parameters are:
|
| setRowData | rowid, data | true on success, otherwise false | Updates the values (using the data array) in the row with rowid. The syntax of data array is: {name1:value1,name2: value2…} where the name is the name of the column as described in the colModel and the value is the new value. |
| setSelection | rowid, onsetselection | jqGrid object | Toggles a selection of the row with id = rowid; if onsetselection is true (the default) then the event onSetRow is launched, otherwise it is not |
| showCol | colname | jqGrid object | Shows a column with a given colname. If the colname is a string we show only the specified column. If colname is array of type ["name1","name2"] then the columns with names 'name1' and 'name2' will be shown at the same time The names in colname must be valid names from colModel. The width of the grid changes by the width of the newly-shown columns. |
| .trigger("reloadGrid"); | none | jqGrid object | Reloads the grid with the current settings. This means that a new request is send to the server if datatype is xml or json.
This method should be applied to an already-constructed grid - e.g.,
jQuery("#grid_id").trigger("reloadGrid"); |
| Option | Returns |
|---|---|
| getGridParam("url") | the current url from options array |
| getGridParam("sortname") | the name of last sorted column |
| getGridParam("sortorder") | the last sorted order |
| getGridParam("selrow") | the id of the selected row, null if row is not selected |
| getGridParam("page") | the current page number. |
| getGridParam("rowNum") | the current number of requested rows |
| getGridParam("datatype") | the current datatype. |
| getGridParam("records") | the current number of records in grid. |
| getGridParam("selarrrow") | array of id's of the selected rows when multiselect options is true. Empty array if not selection. |
| Method | Description |
|---|---|
| setGridParam({url:newvalue}) | Parameters: url - string Set a new url, replacing the older. |
| setGridParam({sortname:newvalue}) | Parameters: sortname - string Set a new sort name |
| setGridParam({sortorder:newvalue}) | Parameters: sortorder - string (asc or desc) Set a new sort order |
| setGridParam({page:newvalue}) | Parameters: page - integer >0 Set a new page number |
| setGridParam({rowNum:newvalue}) | Parameters: rownum - integer > 0 Set a new number of requested rows. |
| setGridParam({datatype:newvalue}) | Parameters: datatype - string (xml,json.xmlstring,jsonstring, clientSide) Set a new datatype. |