关于easyui中datagrid列表checkbox不可用

今天在做项目的时候遇到了一个需求,就是根据状态去判断checkbox是否可用,百度了好多都没有用,所以自己研究并分享出来:

html代码:

<table id="tzml_dataList" width="90%" rownumbers="true"
        data-options="
           iconCls: 'icon-edit',
                                loadMsg: null,
           fitColumns: true,
           nowrap:true,
           method: 'get',
           scrollbarSize:0,
           onClickRow: tzmlEdit">
         <thead data-options="frozen:true">
         <thead>
          <tr>
           <th data-options="field:'ck',checkbox:true"></th>
           <th data-options="field:'px',halign:'center',align:'center',width:27,formatter:getPxh">序号</th>                 
           <th data-options="field:'RQ',width:50,halign:'center',align:'center',
               editor:{type:'datebox',options:{required:true}}">日期</th>
           <th data-options="field:'fj',width:200,align:'center',halign:'center',formatter:getHtml">目录</th>
                 </tr>
               </thead>
       </table>

js代码:

//数据加载成功之后去处理checkbox

$("#"+id).datagrid({rownumbers:false,onLoadSuccess:function(data){
    $("#"+id).datagrid('doCellTip',{cls:{'background-color':'white','font-size':14},delay:100});
    if(id=="tzml_dataList"){
     if (data.rows.length > 0) {
               //循环判断操作为新增的不能选择
               for (var i = 0; i < data.rows.length; i++) {
                   //根据isFinanceExamine让某些行不可选
                   if (data.rows[i].ZT == "3") {
                       $("input[type='checkbox']")[i + 1].disabled = true;
                   }
               }
           }
    }
   }}).datagrid('loadData',dataListJson);

//行点击事件

function tzmlEdit(index,rowData){
   var chechs = $("input[type='checkbox']");
   for(var j=0;j<chechs.length;j++){
    var el = chechs[j].disabled;
    if(el==true){
     $('#tzml_dataList').datagrid('unselectRow',j);
     $('#tzml_dataList').datagrid('uncheckRow',j);
     if(j==index){
      return;
     }
     
    }
   } 
   editData(index,"tzml_dataList");
  }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值