easyUI的formatter使用


<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>  
  1. 比如我對名稱這一欄需要格式設置
<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 !


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM