easyui datagrid获取隐藏列

原创 Laughing  2017-06-30 21:40  阅读 159 次 评论 0 条

问题背景

在我们平时使用easyuidatagrid时,往往会将主键列(guid)进行隐藏,如下代码

  1. $("#dg").datagrid('hideColumn', 'SK_ID');  

对于隐藏的列,我们通过getSelected方法是无法获取到对应的值的,如下方法

  1. var selectRow = $("#dg").datagrid('getSelected');  

解决方法

其实解决方法很简单,只需要设置datagrid的idField属性即可,如下

  1. <table id="dg" class="easyui-datagrid" data-options=" 
  2.            singleSelect:true, 
  3.            collasible:true, 
  4.            idField:'SK_ID', 
  5.            rownumbers:true, 
  6.            iconCls:'icon-view', 
  7.            pagination: true, 
  8.            pageSize: 10, 
  9.            pageList: [5, 10, 30], 
  10.            toolbar:'#toolBar', 
  11.            fit:true"  
  12.            style="width:100%;height:100%;padding:20px">  
  13.         <thead>  
  14.             <tr style="height:32px">  
  15.                 <th data-options="field:'SK_ID',hiden:true">ID</th>  
  16.                 <th data-options=" 
  17.                     field:'SK_Code', 
  18.                     width:'20%', 
  19.                     loadMsg: '数据加载中...', 
  20.                     editor:{ 
  21.                     type:'validatebox', 
  22.                     options:{required:true, 
  23.                     validType:'length[1,100]'} 
  24.                     }">编号</th>  
  25.                 <th data-options=" 
  26.                     field:'SK_Name', 
  27.                     width:'30%', 
  28.                     editor:{ 
  29.                     type:'textbox' 
  30.                     } 
  31.                     ">名称</th>  
  32.                 <th data-options=" 
  33.                     field:'SK_IsStop', 
  34.                     width:'10%', 
  35.                     formatter:function(value,row){ 
  36.                     return value=='0'?'否':'是'; 
  37.                     }, 
  38.                     onAfterEdit:afterEditRow, 
  39.                     editor:{ 
  40.                     type:'combobox', 
  41.                     options:{ 
  42.                     data:yesOrNoJson, 
  43.                     valueField:'id', 
  44.                     textField:'strText'}}">是否停用</th>  
  45.                 <th data-options=" 
  46.                     field:'SK_Note', 
  47.                     width:'40%', 
  48.                     editor:{ 
  49.                     type:'textbox', 
  50.                     options:{ 
  51.                     multiline:true 
  52.                     } 
  53.                     } 
  54.                     ">备注</th>  
  55.             </tr>  
  56.         </thead>  
  57.     </table>  
本文地址:https://www.lisen.me/easyui-datagrid-for-hidden-columns.html
版权声明:本文为原创文章,版权归 木子网 所有,欢迎分享本文,转载请保留出处!

发表评论


表情