<table class="easyui-datagrid" style="width:400px;height:250px" data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true"> <thead> <tr> <th data-options="field:'code',width:100">編碼</th> <th data-options="field:'name',width:100">名稱</th> <th data-options="field:'price',width:100,align:'right'">價格</th> </tr> </thead> </table>
- 比如我對名稱這一欄需要格式設置
<table class="easyui-datagrid" style="width:400px;height:250px" data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true"> <thead> <tr> <th data-options="field:'code',width:100">編碼</th> <th data-options="field:'name',width:100 formatter=formatLink ">名稱</th> <th data-options="field:'price',width:100,align:'right'">價格</th> </tr> </thead> </table>
2.來看一下js代碼實現
單元格formatter(格式化器)函數,帶3個參數: value:字段值。 row:行記錄數據。 index: 行索引。 代碼示例: $('#dg').datagrid({ columns:[[ {field:'name',title:'名稱', width:80, formatter: function(value,row,index){ if (row.code=='1001'){ return val; } else { return null; } } } ]] });
3.或者直接寫一個function formatLink{}
so easyUI !