手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery EasyUI的formatter格式化函数代码
jquery EasyUI的formatter格式化函数代码
摘要:要格式化数据表格列,需要设置formatter属性,该属性是一个函数,它包含两个参数:value:对应字段的当前列的值record:当前行的...

要格式化数据表格列,需要设置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>('+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}

]]

});

对于数字的格式化,可以使用javascript提供的对数字格式化的方法

复制代码 代码如下:

var num=2.4445;

var number=val.toFixed(2);//格式化,保留两位小数

alert(number);

输出:

2.44

【jquery EasyUI的formatter格式化函数代码】相关文章:

js实现异步循环实现代码

jQuery常用知识点总结以及平时封装常用函数

jQuery zTree加载树形菜单功能

动态加载jQuery的方法

使用RequireJS优化JavaScript引用代码的方法

JavaScript中的异常处理方法介绍

jQuery实现延迟跳转的方法

jQuery封装的tab选项卡插件分享

jquery实现的判断倒计时是否结束代码

jQuery替换textarea中换行的方法

精品推荐
分类导航