EasyUI datagrid 格式化显示数据

http://blog.163.com/[email protected]/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. }
时间: 2024-08-24 21:48:30

EasyUI datagrid 格式化显示数据的相关文章

easyui datagrid 每条数据后添加操作按钮

easyui datagrid 每条数据后添加“编辑.查看.删除”按钮 1.给datagrid添加操作字段:字段值 <table class="easyui-datagrid" data-options="singleSelect:true,collapsible:true,url:'publish.json',method:'get',fit:true" style="width: 700px; height: 250px"> &l

实现easyui datagrid在没有数据时显示相关提示内容

本示例实现easyui datagrid加载/查询数据时,如果没有相关记录,则在datagrid中显示没有相关记录的提示信息,效果如下图所示 本实例要实现如下图所示的效果: 本示例easyui版本为1.3.4,如果运行后没有效果,自己检查easyui版本 不同版本对appendRow和mergeCells支持不一样,参数不一致什么的. 无法隐藏分页导航容器,可以用chrome开发工具或者firebug查看分页导航容器的样式和原始datagrid table表格的关系. 源代码如下 $(funct

JS-easyui 扩展easyui.datagrid,添加数据loading遮罩效果代码

(function (){ $.extend($.fn.datagrid.methods, { //显示遮罩 loading: function(jq){ return jq.each(function(){ $(this).datagrid("getPager").pagination("loading"); var opts = $(this).datagrid("options"); var wrap = $.data(this,"

easyui datagrid控制显示进度条

实际项目中当我们在前台分页的时候需要控制datagrid加载数据时显示进度条,而datagrid默认只有在通过url方式加载数据时才显示进度条,以下代码是手动控制: 打开进度条: $('#searchAddrDg').datagrid('loading');//打开等待div 关闭进度条: $('#searchAddrDg').datagrid('loaded');//关闭loding进度条:

扩展easyui.datagrid,添加数据loading遮罩效果代码 --来自网摘收集

//jquery.datagrid 扩展 (function (){ $.extend($.fn.datagrid.methods, { //显示遮罩 loading: function(jq){ return jq.each(function(){ $(this).datagrid("getPager").pagination("loading"); var opts = $(this).datagrid("options"); var wra

在easyui datagrid中formatter数据后使用linkbutton

http://ntzrj513.blog.163.com/blog/static/2794561220139245411997/ formatter:function(value,rowData,rowIndex){ if(value==""||value==null){ return "未知"; return rowData.cname+"<a class='easyui-linkbutton' data-options=\"iconCl

【解决方法】EasyUI DataGrid不显示滚动条时,没有数据的问题

解决方法 于dataGrid例如,下面的代码被添加到的定义: JavaScript Code 1 2 3 4 5 6 7 8 9 10 onLoadSuccess : function (data) { if (data.total == 0) { $('#dg').datagrid('insertRow', { row : {} }); $("#dg").parent().find("tr[datagrid-row-index='0']").css({ "

ssm+easyUI datagrid 不能显示后台controller层返回的json数据

后台打印查询出来的数据: {"total":29,"rows":[{"department_id":0,"department_name":"董事会办公室","id":1,"idcard":"3423243543534","phone":"15155157074","rname":&quo

easyui datagrid 格式化列显示两位小数、千分位

{ field: "contractmoney", title: "合同总价", width: 72, formatter: function (value, row, index) { if (row != null) { return parseFloat(value).toFixed(2); } } }, //二位小数.千分位 { field: "price", title: "单价", width: 60, align