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