jqGrid常用事件方法总结-飞外

获取选中多行数据varids =$$("#jqGrid").jqGrid("getGridParam", "selarrrow");
varrowDatas =$$.map(ids,function(v){ return $$("#jqGrid").jqGrid("getRowData", v)});

单元格保存$$("#jqGrid").saveCell($$('#jqGrid').jqGrid('getGridParam','iRow'), $$('#jqGrid').jqGrid('getGridParam','iCol'));
设置列显示隐藏$$('#jqGrid').setGridParam().hideCol('colName'); //colName 是设置列的名称
$$('#jqGrid').setGridParam().showCol('colName');
设置单元格值 $$("#jqGrid").jqGrid('setCell', rowid ,colname , data,class,properties);
或$$("#jqGrid").setCell( rowid ,colname , data,class,properties);
{label:'序号', name: "rn", 40, labelClasses: "jqgh_rn", sortable: false, resizable: false, hidedlg: true, search: false, align: "center", fixed: true, frozen: true}

rowidrowdatarowelem当插入每行时触发。rowid插入当前行的id;rowdata插入行的数据,格式为name: value,name为colModel中的名字
rowid, e当用户点击当前行在未选择此行时触发。rowid:此行id;e:事件对象。返回值为ture或者false。如果返回true则选择完成,如果返回false则不会选择此行也不会触发其他事件
当表格所有数据都加载完成而且其他的处理也都完成时触发此事件,排序,翻页同样也会触发此事件
xhr,status,error如果请求服务器失败则调用此方法。xhr:XMLHttpRequest对象;satus:错误类型,字符串类型;error:exception对象
rowid,iCol,cellcontent,e当点击单元格时触发。rowid:当前行id;iCol:当前单元格索引;cellContent:当前单元格内容;e:event对象
rowid,iRow,iCol,e双击行时触发。rowid:当前行id;iRow:当前行索引位置;iCol:当前单元格位置索引;e:event对象
gridstate当点击显示/隐藏表格的那个按钮时触发;gridstate:表格状态,可选值:visible or hidden
rowid,iRow,iCol,e在行上右击鼠标时触发此事件。rowid:当前行id;iRow:当前行位置索引;iCol:当前单元格位置索引;e:event对象
aRowids,statusmultiselect为ture,且点击头部的checkbox时才会触发此事件。aRowids:所有选中行的id集合,为一个数组。status:boolean变量说明checkbox的选择状态,true选中false不选中。无论checkbox是否选择,aRowids始终有值
rowid,status当选择行时触发此事件。rowid:当前行id;status:选择状态,当multiselect为true时此参数才可用
index,iCol,sortorder当点击排序列但是数据还未进行变化时触发此事件。index:name在colModel中位置索引;iCol:当前单元格位置索引;sortorder:排序状态:desc或者asc
event, index当开始改变一个列宽度时触发此事件。event:event对象;index:当前列在colModel中位置索引
newwidth, index当列宽度改变之后触发此事件。newwidth:列改变后的宽度;index:当前列在colModel中的位置索引
使用传来的data数据填充表格。使用方法:var mygrid = jQuery(”#”+grid_id)[0]; var myjsongrid = eval(”(”+jsonresponse.responseText+”)”); mygrid.addJSONData(myjsongrid); myjsongrid = null; jsonresponse =null;
成功为true,否则为false根据参数插入一行新的数据,rowid为新行的id,data为新行的数据,position为新增行的位置,srcrowid为新增行的参考位置。data数据格式:{name1:value1,name2: value2…} name为在colModel中指定的名称
根据传来的数据填充表格。用法:var mygrid = jQuery(”#”+grid_id)[0]; mygrid.addXmlData(xmlresponse.responseXML);
jqGrid对象清除表格当前加载的数据。如果clearfooter为true时则此方法删除表格最后一行的数据
jgGrid对象设置或者取得底部数据。action:“get”或者“set”,默认为“get”,如果为“get”返回值为name:value,name为colModel中名称。如果为“set”则值为name:value,name是colModel中的名称。format:默认为true,当为true时,在设置新值时会调用formatter格式化数值
单元格内容返回指定rowid,iCol的单元格内容,iCol既可以是当前列在colModel中的位置索引也可以是name值。注意:在编辑行或者单元格时不能使用此方法,此时返回的并不是改变的值,而是原始值
array[] or value返回列的值。colname既可以是当前列在colModel中的位置索引也可以是name值。returntype指定返回数据的类型,默认为false。当为false时,返回的数组中只包含列的值,当为true时返回数组是对象数组,具体格式{id:rowid, value:cellvalue},id为行的id,value为列的值。如:[{id:1,value:1},{id:2,value:2}…]。mathoperation可选值为'sum, 'avg', 'count'
mixed如果rowcontent为false,返回行所在的索引位置,id为行id。rowcontent默认为false。如果rowconent为ture则返回的为行对象,如果找不到行则返回false
array[]返回指定行的数据,返回数据类型为name:value,name为colModel中的名称,value为所在行的列的值,如果根据rowid找不到则返回空。在编辑模式下不能用此方法来获取数据,它得到的并不是编辑后的值
jqGrid对象如果参数为一个列名则隐藏此列,如果给定的是数组则隐藏指定的所有列。格式:[“name1”,”name2”]
调整表格列的显示顺序,permutation为当前列的顺序,假如值是[1,0,2],那么第一列就会在第二位显示。如果updateCells为ture则是对单元格数据进行重新排序,如果keepHeader为true则对header数据显示位置进行调整
jqGrid对象改变单元格的值。rowid:当前行id;colname:列名称,也可以是列的位置索引,从0开始;data:改变单元格的内容,如果为空则不更新;class:如果是string则会使用addClass方法将其加入到单元格的css中,如果是array则会直接加到style属性中;properties:设置单元格属性
jqGrid对象设置grid的参数。有些参数的修改必须要重新加载grid才可以生效,这个方法可以覆盖事件
jqGrid对象动态改变grid的高度,只能对单元格的高度进行设置而不能对表格的高度进行动态修改。new_height:可以是象素值,百分比或者"auto"
jqGrid对象动态改变表格的宽度。new_表格宽度,象素值;shrink:true或者false,作用同shrinkToFit
jqGrid对象给指定列设置一个新的显示名称。colname:列名称,也可以是列的位置索引,从0开始;data:列显示名称,如果为空则不修改;class:如果是string则会使用addClass方法将其加入到单元格的css中,如果是array则会直接加到style属性中;properties:设置label的属性
成功true否则false更新行的值,rowid为行id。data值格式:{name1:value1,name2: value2…} name为colModel中名称;cssprop:如果是string则会使用addClass方法将其加入到行的css中,如果是array或者对象则会直接加到style属性中
jqGrid对象选择或反选指定行。如果onselectrow为ture则会触发事件onSelectRow,onselectrow默认为ture
jqGrid显示列。colname可以是数组[“name1”,”name2”],但是name1或者name2必须是colModel中的name
同步表格的宽度,用在表格拖拽时,用法:var mygrid=jQuery(”#grid_id”)[0];mygrid.updateColumns();
rowid, 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
rowid, 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
rowid, 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.
serverresponse, 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.
rowid, cellname, value, iRow, iColapplies only to a cell that is editable; this event fires before editing the cell.
rowid, 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”
rowid, 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.
serverresponse, 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.
rowid, 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
rowid, celname, value, iRow, iColapplies only to cells that are not editable; fires after the cell is selected
postdataIf 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
formatCell(rowid, cellname, value, iRow, iCol) : You can change the cell value here which will be used in the edit mode
beforeEditCell(rowid, cellname, value, iRow, iCol) : Just before the cell jumps into edit mode this event is fired
afterEditCell(rowid, cellname, value, iRow, iCol) : Just after the input element is created this event will be fired
beforeSaveCell(rowid, cellname, value, iRow, iCol) : Fires before the cell is saved, you can save the value here which is send to the server.
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
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
afterSaveCell(rowid, cellname, value, iRow, iCol) : Fires when the value of the cell is saved
errorCell(serverresponse, status) : Fires when a server error is occured (like: 403, 404, 500, etc)
onSelectCell(rowid, celname, value, iRow, iCol) : Fires when a cell is not editable
formatCell(rowid, cellname, value, iRow, iCol) : You can change the cell value here which will be used in the edit mode
beforeEditCell(rowid, cellname, value, iRow, iCol) : Just before the cell jumps into edit mode this event is fired
afterEditCell(rowid, cellname, value, iRow, iCol) : Just after the input element is created this event will be fired
beforeSaveCell(rowid, cellname, value, iRow, iCol) : Fires before the cell is saved by user
beforeSubmitCell(rowid, cellname, value, iRow, iCol) : You can save the value somewhere here
afterSaveCell(rowid, cellname, value, iRow, iCol) : Fires when the value of the cell is succesfully saved by beforeSubmitCell
onSelectCell(rowid, celname, value, iRow, iCol) : Fires when a cell is not editable


iRow, 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.
methodReturns 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
iRow, iColrestores the edited content of cell with the row index iRow( do not mix with rowid) in index column iCol
iRow, iColsaves the cell with the row index iRow( do not mix with rowid) in index column iCol