• EasyUI 格式化列


    以下实例格式化在 easyui DataGrid 里的列数据,并使用自定义列的 formatter,如果价格小于 20 就将文本变为红色。

    为了格式化一个数据网格(DataGrid)列,我们需要设置 formatter 属性,它是一个函数。这个格式化函数包含三个参数:

    • value:当前列对应字段值。
    • row:当前的行记录数据。
    • index:当前的行下标。

    创建数据网格(DataGrid)

    1. <table id="tt" title="Formatting Columns" class="easyui-datagrid" style="width:550px;height:250px"
    2. url="data/datagrid_data.json"
    3. singleSelect="true" iconCls="icon-save">
    4. <thead>
    5. <tr>
    6. <th field="itemid" width="80">Item ID</th>
    7. <th field="productid" width="80">Product ID</th>
    8. <th field="listprice" width="80" align="right" formatter="formatPrice">List Price</th>
    9. <th field="unitcost" width="80" align="right">Unit Cost</th>
    10. <th field="attr1" width="100">Attribute</th>
    11. <th field="status" width="60" align="center">Stauts</th>
    12. </tr>
    13. </thead>
    14. </table>

    请注意,'listprice' 字段有一个 'formatter' 属性,用来指明格式化函数

    写格式化函数

    1. function formatPrice(val,row){
    2. if (val < 20){
    3. return '<span style="color:red;">('+val+')</span>';
    4. } else {
    5. return val;
    6. }
    7. }
  • 相关阅读:
    Linux
    python中元类
    POJ 1182 食物链
    POJ 1733 Parity game
    top 介绍
    周记 2014.8.31
    windows10配置python
    oracle执行update时卡死问题的解决办法
    An Easy Introduction to CUDA C and C++
    super()
  • 原文地址:https://www.cnblogs.com/zkwarrior/p/4843899.html
Copyright © 2020-2023  润新知