1. 程式人生 > 其它 >easyui datagrid th標籤列數字保留2位小數

easyui datagrid th標籤列數字保留2位小數

技術標籤:easyuieasyuic#

easyui datagrid th標籤列數字保留2位小數

在th標籤內新增data-options=“formatter:formatState”,然後在腳本里編寫formatState方法就可啦!
單元格formatter(格式化器)函式,帶3個引數:
value:欄位值。
row:行記錄資料。
index: 行索引。

<table id="gridlist" data-bind="datagrid:grid">
    <thead>
        <tr>
         .
..若干程式碼.... <th field="TotalAmount" sortable="true" align="right" width="100" data-options="formatter:formatState">配件金額</th> <th field="TotalWorkHours" sortable="true" align="right" width=
"100" data-options="formatter:formatState">總工時 </th> </tr> </thead> </table> <script type="text/javascript"> function formatState(value, row, index) { if (row != null) { return parseFloat
(value).toFixed(2); } } </script>

結果圖片示例:在這裡插入圖片描述