JqGrid单元格编辑配置方法

jqGrid单元格编辑配置方法:

配置

表格配置项
{
    url: baseURL + 'company/list',
    datatype: "json",
    colModel: cols,
    cellEdit: true, 
    cellurl: 'company/update', 
    cellsubmit: 'remote',
    viewrecords: true,
    height: 385
}

需要配置的是cellEdit、cellurl、cellsubmit三个字段(ajaxCellOptions)。官方文档对这些字段的说明如下:

属性类型描述默认值
cellEditboolean开启单元格编辑支持。当值为true时,onSelectRow事件将不能使用,而且hovering也会被禁用false
cellsubmitstring决定单元格编辑的数据保存到哪里。可以有两个值:‘remote’或’clientArray’。如果选择remote模式,当单元格数据改变时会马上通过cellurl配置的接口以ajax的方式发送到服务端。rowid和编辑内容会被默认以query string的形式添加到url上。如果mtype设为post,则以键值对发送post请求。如果不想直接提交到服务端,可以选择clientArray模式,再通过getChangedCells方法拿到修改后的值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
监听事件
事件参数说明:
  • rowid - is the id of the row
  • cellname is the name of the cell (name from colModel)
  • value - the value of the cell
  • iRow - the index of the row (do not mix with rowid)
  • iCol - the index of the column
常用的事件:
  • beforeSubmitCell(rowid, cellname, value, iRow, iCol) :
    在请求发起前触发,可以return新的数组或对象用来作为请求参数。例如:
if( some_condition ) {
    return {name1:value1,name2:value2}
} else { 
    return {}
}
  • formatCell(rowid, cellname, value, iRow, iCol) :
    这个方法可以在编辑单元格之前,对单元格的内容格式化。
事件调用栈(触发顺序)

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

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
列配置项

在需要编辑的列定义里面加上:

editable: true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值