1.通过HTML标签创建数据表格时使用formatter

<!DOCTYPE html>
<html> <head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = {
"rows": [{
"stuName": "李斯",
"stuAge": 23
}, {
"stuName": "白起",
"stuAge": 25
}],
"total": 2
}
$('#tt').datagrid('loadData',data);
}) //value:字段值;row:行记录数据;index: 行索引
function formatPrice(value,row,index) {
if(value>=20){
return '<span style="color:blue;">' + value + '</span>';
}
}
</script>
</head> <body>
<table id="tt" title="studentInfo" class="easyui-datagrid" style="width:300px;height:250px">
<thead>
<tr>
<th field="stuName" width="80">学生姓名</th>
<th field="stuAge" width="80" formatter="formatPrice">学生年龄</th>
</tr>
</thead>
</table>
</body> </html>

2.通过JS创建数据表格时使用formatter

<!DOCTYPE html>
<html> <head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var data = {
"rows": [{
"stuName": "李斯",
"stuAge": 23
}, {
"stuName": "白起",
"stuAge": 25
}],
"total": 2
} $("#tt").datagrid({
columns: [
[{
field: 'stuName',
title: '学生姓名',
width: 80
},
{
field: 'stuAge',
title: '学生年龄',
width: 80,
formatter: function(value, row, index) {
if(value >= 20) {
return '<span style="color:blue;">' + value + '</span>';
}
}
}
]
] }).datagrid('loadData', data);
})
</script>
</head> <body>
<table id="tt" title="studentInfo" style="width:300px;height:250px"></table>
</body> </html>

最新文章

  1. linux 权限
  2. HomeWork2
  3. c#网络通信框架networkcomms内核解析之九 自定义处理方法的运行机制
  4. spring读写分离
  5. BZOJ3238 [Ahoi2013]差异
  6. Java基本类型
  7. 约瑟夫环(N个人围桌,C语言,数据结构)
  8. 学习CTF的经历-文件分析
  9. javascript中的自定义属性
  10. JavaScript线程(第八天)
  11. RabbitMQ安装及使用
  12. nginx代理后,获取request的ip
  13. 从数据库中修改zabbix的验证方式 0 内置 1 LDAP 2 HTTP
  14. rhel7磁盘管理
  15. php 爬虫简单示例
  16. 人人,金山西山居,腾讯互娱,微信,网易游戏offer及面经
  17. Python:笔记(6)——正则表达式
  18. Flask中路由原理
  19. Alpha冲刺(6/10)——追光的人
  20. Caffe2——C++ 预测(predict)Demo

热门文章

  1. 使用git创建与合并分支
  2. flume学习笔记——安装和使用
  3. Springboot多数据源配置--数据源动态切换
  4. 【netcore基础】CentOS 7.6.1810 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动
  5. TTL是什么意思?
  6. 初识springcloud
  7. vue项目实战中的增、删、改、查
  8. Codeforces Round #498 (Div. 3)
  9. poj3278Catch That Cow
  10. 支持多文件上传,预览,拖拽,基于bootstrap的上传插件fileinput 的ajax异步上传(转载)