[转载]easyui datagrid 行内编辑功能


EASY UI 中文官网给出了行内编辑demo:http://www.jeasyui.net/tutorial/36.html,但是updateActions方法实际使用并不成功,在网上查了很久,总算找到了替代方法,即使用

$('#tt').datagrid('refreshRow', index)

替代demo中的

$('#tt').datagrid('updateRow',{
				index: index,
				row:{}
			});

具体代码转载如下。此外还需注意的是,当row处于编辑开启的状态时,无论如何修改值,直到行编辑关闭前,使用 row.field 获取到的值均是编辑开启之前的值。对编辑后的新值做处理,需在 onAfterEdit 中进行。


以下部分转载自 http://www.cnblogs.com/babietongtianta/p/3765484.html#undefined  侵删!


$( '#tt' ).datagrid({
     title: 'Editable DataGrid' ,
     iconCls: 'icon-edit' ,
     width:660,
     height:250,
     singleSelect: true ,
     idField: 'itemid' ,
     url: 'datagrid_data.json' ,
     columns:[[
         {field: 'itemid' ,title: 'Item ID' ,width:60},
         {field: 'productid' ,title: 'Product' ,width:100,
             formatter: function (value){
                 for ( var  i=0; i<products.length; i++){
                     if  (products[i].productid == value)  return  products[i].name;
                 }
                 return  value;
             },
             editor:{
                 type: 'combobox' ,
                 options:{
                     valueField: 'productid' ,
                     textField: 'name' ,
                     data:products,
                     required: true
                 }
             }
         },
         {field: 'listprice' ,title: 'List Price' ,width:80,align: 'right' ,editor:{type: 'numberbox' ,options:{precision:1}}},
         {field: 'unitcost' ,title: 'Unit Cost' ,width:80,align: 'right' ,editor: 'numberbox' },
         {field: 'attr1' ,title: 'Attribute' ,width:150,editor: 'text' },
         {field: 'status' ,title: 'Status' ,width:50,align: 'center' ,
             editor:{
                 type: 'checkbox' ,
                 options:{
                     on:  'P' ,
                     off:  ''
                 }
             }
         },
         {field: 'action' ,title: 'Action' ,width:70,align: 'center' ,
             formatter: function (value,row,index){
                 if  (row.editing){
                     var  s =  '<a href="#" onclick="saverow(' +index+ ')">Save</a> ' ;
                     var  c =  '<a href="#" onclick="cancelrow(' +index+ ')">Cancel</a>' ;
                     return  s+c;
                 else  {
                     var  e =  '<a href="#" onclick="editrow(' +index+ ')">Edit</a> ' ;
                     var  d =  '<a href="#" onclick="deleterow(' +index+ ')">Delete</a>' ;
                     return  e+d;
                 }
             }
         }
     ]],
     onBeforeEdit: function (index,row){
         row.editing =  true ;
         $( '#tt' ).datagrid( 'refreshRow' , index);
     },
     onAfterEdit: function (index,row){
         row.editing =  false ;
         $( '#tt' ).datagrid( 'refreshRow' , index);
     },
     onCancelEdit: function (index,row){
         row.editing =  false ;
         $( '#tt' ).datagrid( 'refreshRow' , index);
     }
});

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
easyui datagrid 中实现行内编辑 checkbox 可以通过以下步骤: 1. 在 datagrid 的 columns 属性中添加一个 checkbox 列: ``` { field: 'checked', title: 'Checked', checkbox: true }, ``` 2. 在 datagrid 的 onBeforeEdit 事件中设置 checkbox 列的编辑器为 null,即禁用编辑功能: ``` onBeforeEdit: function(index, row) { $('#datagrid').datagrid('getColumnOption', 'checked').editor = null; }, ``` 3. 在 datagrid 的 onAfterEdit 事件中获取 checkbox 列的值并更新到对应的数据行中: ``` onAfterEdit: function(index, row, changes) { var checked = $('#datagrid').datagrid('getEditor', {index: index, field: 'checked'}); row.checked = $(checked.target).is(':checked'); $('#datagrid').datagrid('refreshRow', index); }, ``` 这样就可以实现行内编辑 checkbox 功能了。完整的代码示例可以参考下面的例子: ``` $('#datagrid').datagrid({ url: 'datagrid_data.json', columns: [[ { field: 'id', title: 'ID', width: 50 }, { field: 'name', title: 'Name', width: 100, editor: 'text' }, { field: 'checked', title: 'Checked', checkbox: true } ]], onBeforeEdit: function(index, row) { $('#datagrid').datagrid('getColumnOption', 'checked').editor = null; }, onAfterEdit: function(index, row, changes) { var checked = $('#datagrid').datagrid('getEditor', {index: index, field: 'checked'}); row.checked = $(checked.target).is(':checked'); $('#datagrid').datagrid('refreshRow', index); }, toolbar: [{ text: 'Save', iconCls: 'icon-save', handler: function() { $('#datagrid').datagrid('endEdit', 0); } }] }); ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值