Easyui DataGrid formatted display data

Source: Internet
Author: User

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
  1. <table id= "tt" title= "Formatting Columns" class= "Easyui-datagrid" style= "width:550px;height:250px"
  2. Url= "Data/datagrid_data.json"
  3. Singleselect= "true" iconcls= "Icon-save" >
  4. <thead>
  5. <tr>
  6. <th field= "itemid" width= ">item id</th>"
  7. <th field= "ProductID" width= ">product id</th>"
  8. <th field= "ListPrice" width= "Up" align= "right" formatter= "Formatprice" >list price</th>
  9. <th field= "UnitCost" width= "Up" align= "right" >unit cost</th>
  10. <th field= "attr1" width= ">Attribute</th>"
  11. <th field= "status" width= "align= Center" >Stauts</th>
  12. </tr>
  13. </thead>
  14. </table>
Note that the ' ListPrice ' field has a ' formatter ' attribute that indicates a format function.

Write formatting functions
    1. function Formatprice (val,row) {
    2. if (Val < 20) {
    3. Return ' <span style= ' color:red; > (' +val+ ') </span> ';
    4. } else {
    5. return Val;
    6. }
    7. }

Easyui DataGrid formatted display data

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.