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