Formatter Function Code of jquery EasyUI

Source: Internet
Author: User

To Format a data table, you need to set the formatter attribute, which is a function and contains two parameters:

Value: the value of the current column of the corresponding field.
Record: record Data of the current row
Copy codeThe 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: 'produd d', 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}
]
});

You can use javascript to format numbers.
Copy codeThe Code is as follows:
Var num = 2.4445;
Var number = val. toFixed (2); // format, retain 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.