jQuery EasyUI DataGrid - Formatting Columns
The following example formats column data in an easyui DataGrid using a custom column formatter; if the price is less than 20, the text is turned red.
To format a DataGrid column, we need to set the formatter property, which is a function. This formatting function takes three parameters:
- value: the field value corresponding to the current column.
- row: the current row's record data.
- index: the current row's index.
Create the DataGrid
Item ID
Product ID
List Price
Unit Cost
Attribute
Stauts
Note that the 'listprice' field has a 'formatter' property that indicates the formatting function.
Write a formatter function
function formatPrice(val,row){
if (val < 20){
return '('+val+')';
} else {
return val;
}
}