EasyUI datagrid 格式化显示数据

http://blog.163.com/ppy2790@126/blog/static/103242241201512502532379/

设置formatter属性,是一个函数,格式化函数有3个参数:
The cell formatter function, take three parameters:
value: the field value.
rowData: the row record data.
rowIndex: the row index.
 
一、格式化显示性别
后台传过来的json中性别值是0、1,页面显示时调用格式化函数:
(js方式)

{

    title : '性别',

    field : 'gender',

    width : 50,

    formatter:function(value,rec){

 return rec.gender==0?'女':'男';

    }

}

 
二、格式化显示时间

{

title : '回访日期',

field : 'date',

width : 120,

formatter: function (value, rec, index) {

        if (value == undefined) {

            return "";

        }

        /*json格式时间转js时间格式*/

       var date = new Date(value);

        

                       return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()+'  '+date.getHours()+":"+date.getMinutes();

     

    }

}, 

 
三、格式化显示数据样式
格式化小于20的价格显示红色(Html方式)
创建 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. }    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值