EasyUI 的datagrid 有的时候需要直接给某列固定值(如操作列 全为删除),或对数据进行格式化,这就需要formatter属性,如果
<table style="width: 600px" class="easyui-datagrid"
data-options="title:'岗位信息列表',url:'position.json',fitColumns:true,rownumbers:true,singleSelect:true,method:'get'">
<thead>
<tr>
<th data-options="field:'name',width:2">
岗位名称
</th>
<th data-options="field:'desc',width:3">
岗位描述
</th>
<th formatter="formatOp" data-options="field:'id',width:1">
操作
</th>
</tr>
</thead>
</table>
在使用中要注意的是, 如果某列的 field值,在前面已经出现过,则后出现的同field列,将按第一次出现的field列使用。如果第一次出现的field同值的列没有formatter,后续的formatter将无效
处理办法,是将后续的出现的列的field改成 任意不存在的列即可,注意:不能是空字符串
如果在formatter函数中需要使用某属性的值,可通过
function(value,rowData,rowIndex) 第二个参数rowData.属性名访问