jquery Easyui Formatter Format function code _jquery

Source: Internet
Author: User
To format a data table column, you set the Formatter property, which is a function that contains two parameters:

Value: Values for the current column of the corresponding field
Record: Recording data for current row
Copy Code code 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 ' <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}
]]
});

For numeric formatting, you can use JavaScript-provided methods for formatting numbers
Copy Code code as follows:

var num=2.4445;
var number=val.tofixed (2);//formatting, reserving two decimal places
alert (number);

Output:
2.44

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.