easyui formatter用法,转载

以下实例格式化数据表格中的一列。如果金额小于20时使用自定义的格式器将文本变成红色。

要格式化数据表格列,需要设置formatter属性,该属性是一个函数,它包含两个参数:

value: 对应字段的当前列的值 
record: 当前行的记录数据

$(‘#tt‘).datagrid({ 
title:‘Formatting Columns‘, 
width:550, 
height:250, 
url:‘datagrid_data.json‘, 
columns:[[ 
{field:‘itemid‘,title:‘Item ID‘,width:80}, 
{field:‘productid‘,title:‘Product ID‘,width:80}, 
{field:‘listprice‘,title:‘List Price‘,width:80,align:‘right‘, 
formatter:function(val,rec){ 
if (val < 20){ 
return ‘<span style="color:red;">(‘+val+‘)</span>‘; 
} else { 
return val; 


}, 
{field:‘unitcost‘,title:‘Unit Cost‘,width:80,align:‘right‘}, 
{field:‘attr1‘,title:‘Attribute‘,width:100}, 
{field:‘status‘,title:‘Status‘,width:60} 
]] 
});

///下面是w3cschool的例子:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<title>jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="http://www.w3cschool.cc/try/jeasyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.w3cschool.cc/try/jeasyui/themes/icon.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://www.w3cschool.cc/try/jeasyui/jquery.easyui.min.js"></script>
<script>
function formatPrice(val,row){
if (val < 20){
return ‘<span style="color:red;">(‘+val+‘)</span>‘;
} else {
return ‘<span style="color:green;">(‘+val+‘)</span>‘;
}
}
</script>
</head>
<body>
<h1>DataGrid</h1>

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

</body>
</html>

easyui formatter用法,转载

时间: 2024-08-27 20:43:28

easyui formatter用法,转载的相关文章

EasyUI——常见用法总结

EasyUI——常见用法总结 1. 使用 data-options 来初始化属性. data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我们可以对easyui组件的实例化可以完全写入到html中,例如: <div class="easyui-dialog" style="width:400px;height:200px" data-options="title:'My Dialog',collapsi

elasticsearch的基本用法(转载)

最大的特点:  1. 数据库的 database, 就是  index  2. 数据库的 table,  就是 tag  3. 不要使用browser, 使用curl来进行客户端操作.  否则会出现 java heap ooxx... curl:  -X 后面跟 RESTful :  GET, POST ...  -d 后面跟数据. (d = data to send) 1. create: 指定 ID 来建立新记录. (貌似PUT, POST都可以)  $ curl -XPOST localh

mysql中count,GROUP BY的用法(转载)

计算你拥有动物的总数目与“在pet表中有多少行?”是同样的问题,因为每个宠物有一个记录.COUNT(*)函数计算行数,所以计算动物数目的查询应为: mysql> SELECT COUNT(*) FROM pet;+----------+| COUNT(*) |+----------+|        9 |+----------+在前面,你检索了拥有宠物的人的名字.如果你想要知道每个主人有多少宠物,你可以使用COUNT( )函数: mysql> SELECT owner, COUNT(*) F

AndroidDrawable那些不为人知的高效用法(转载)

AndroidDrawable那些不为人知的高效用法 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/43752383,本文出自:[张鸿洋的博客] 1.概述 Drawable在我们平时的开发中,基本都会用到,而且给大家非常的有用.那么什么是Drawable呢?能够在canvas上绘制的一个玩意,而且相比于View,并不需要去考虑measure.layout,仅仅只要去考虑如何draw(canavs).当然了,对于Drawable

linux—sed 用法-转载

linux中sed的用法 sed命令行格式为:         sed [-nefri]  'command'  输入文本/文件 常用选项:        -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的用法中,所有来自 STDIN的资料一般都会被列出到屏幕上.但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作)才会被列出来        -e∶进行多项编辑,即对输入行应用多条sed命令时使用. 直接在指令列模式上进行 sed 的动作编辑       

SQL中CASE 的用法 转载

sql语言中有没有类似C语言中的switch case的语句?? 没有,用case   when   来代替就行了.              例如,下面的语句显示中文年月 select getdate() as 日期,case month(getdate()) when 11 then '十一' when 12 then '十二' else substring('一二三四五六七八九十', month(getdate()),1) end+'月' as 月份 ===================

Java中Timer的用法--转载之网络

用法很简单,new一个timer,然后写一个timertask的子类即可. import java.util.Timer; import java.util.TimerTask; public class M { public static void main(String[] args) { // TODO todo.generated by zoer Timer timer = new Timer(); timer.schedule(new MyTask(), 1000, 2000); }

JQuery EasyUI window 用法

JQuery代码 var $win; $win = $('#test-window').window({ title: '添加课程设置信息', width: 820, height: 450, top: ($(window).height() - 820) * 0.5, left: ($(window).width() - 450) * 0.5, shadow: true, modal: true, iconCls: 'icon-add', closed: true, minimizable:

C#中Dictionary的用法 [转载]

在C#中,Dictionary提供快速的基于兼职的元素查找.他的结构是这样的:Dictionary<[key], [value]> ,当你有很多元素的时候可以使用它.它包含在System.Collections.Generic名空间中.在使用前,你必须声明它的键类型和值类型. 要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) Dictionary的描述 1.从一组键(Key)到一组值(Value)的映射,