Http://blog.163.com/[email protected]/blog/static/103242241201512502532379/
Setting the Formatter property is a function, and the Format function has 3 parameters: the cell formatter function, take three parameters:
value:the field value.
Rowdata:the row record data.
Rowindex:the row index. First, formatted to show the sex background of the JSON in the gender value is 0, 1, the page display call Format function: (JS mode)
{
Title: ' Gender ',
Field: ' Gender ',
WIDTH:50,
Formatter:function (Value,rec) {
return rec.gender==0? ' Female ': ' Male ';
}
}
Second, the format of display time
{
Title: ' Return Date ',
Field: ' Date ',
WIDTH:120,
Formatter:function (value, REC, index) {
if (value = = undefined) {
Return "";
}
/*json format time to JS time format */
var date = new Date (value);
return date.getfullyear () + '-' + (Date.getmonth () + 1) + '-' + date.getdate () + ' +date.gethours () + ":" +date.getminutes ();
}
},
Formatting display data style formatting less than 20 price display red (HTML) create a DataGrid
- <table id= "tt" title= "Formatting Columns" class= "Easyui-datagrid" style= "width:550px;height:250px"
- Url= "Data/datagrid_data.json"
- Singleselect= "true" iconcls= "Icon-save" >
- <thead>
- <tr>
- <th field= "itemid" width= ">item id</th>"
- <th field= "ProductID" width= ">product id</th>"
- <th field= "ListPrice" width= "Up" align= "right" formatter= "Formatprice" >list price</th>
- <th field= "UnitCost" width= "Up" align= "right" >unit cost</th>
- <th field= "attr1" width= ">Attribute</th>"
- <th field= "status" width= "align= Center" >Stauts</th>
- </tr>
- </thead>
- </table>
Note that the ' ListPrice ' field has a ' formatter ' attribute that indicates a format function.
Write formatting functions
- function Formatprice (val,row) {
- if (Val < 20) {
- Return ' <span style= ' color:red; > (' +val+ ') </span> ';
- } else {
- return Val;
- }
- }
Easyui DataGrid formatted display data