• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
子目枫林
博客园    首页    新随笔    联系   管理    订阅  订阅

EasyUI datagrid formatter 属性

easyui的formatter属性可以帮助我们更加灵活的显示数据库中的数据。

 

比如,我有一个启用禁用字段,使用数字表示,1表示启用,2表示禁用,展示给客户的时候我当然希望是中文的形式。

 

只需要写这么一个formatter方法:(isu就是这个字段)


function formatterIsu(value, row, index){
if(row.isu==1){
return "启用";
}else if(row.isu==2){
return "禁用";
}
}

然后在<th>标签里的将这个函数赋值给formatter属性:

 


最后页面上输出的就是中文的启用,禁用了。

很多时候,创建表格头也是通过js来完成,里面也是可以加入formatter函数来格式化字段的:


$(document).ready(function() {
$('#dg').datagrid({
url : "/bboo/resource/gj-resource!queryResource.do",
columns : [ [ {
field : 'resourceId',
title : '菜单id',
width : 50,
sortable : true
}, {
field : 'description',
title : '描述',
width : 50,
sortable : true
}, {
field : 'name',
title : '名称',
width : 50,
sortable : true
}, {
field : 'sort',
title : '分类',
width : 50,
sortable : true
}, {
field : 'type',
title : '类型',
width : 50,
sortable : true
}, {
field : 'value',
title : 'url值',
width : 50,
sortable : true
}, {
field : 'pid',
title : '父菜单',
width : 80,
formatter : function(value, row, index) {
if (row.parent) {
return row.parent.resourceId;
} else {
return value;
}
}
} ] ]
});
});

上面的pid字段就是格式化后的数据。

 

posted @ 2018-12-05 09:09  子目枫林  阅读(871)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3