Easyui formatter usage, reprinted

Source: Internet
Author: User
The following example shows how to format a column in a data table. If the amount is less than 20, use the custom formatter to convert the text to red. 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

$ ('# 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}
]
});
/// The following is an example of w3cschool:
View code

 

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.