Home > Web Front-end > JS Tutorial > jquery EasyUI formatter formatting function code_jquery

jquery EasyUI formatter formatting function code_jquery

WBOY
Release: 2016-05-16 18:12:00
Original
1476 people have browsed it

To format a data table column, you need to set the formatter attribute, which is a function that contains two parameters:

value: the value of the current column of the corresponding field
record: the record data of the current row

Copy code The code is as follows:

$('#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 '(' val ')';
} else {
return val;
}
}
},
{field:'unitcost',title :'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:100},
{field:'status',title: 'Status',width:60}
]]
});

For number formatting, you can use the number formatting method provided by javascript
Copy code The code is as follows:

var num=2.4445;
var number=val.toFixed(2) ;//Format, keep two decimal places
alert(number);

Output:
2.44
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template