Easyui Formatting columns

Source: Internet
Author: User

The following instance formats the column data in the Easyui DataGrid and uses the formatter of the custom column to turn the text red if the price is less than 20.

In order to format a data grid (DataGrid) column, we need to set the formatter property, which is a function. This format function contains three parameters:

    • Value: The current column corresponds to the field value.
    • Row: The current row record data.
    • Index: The current row subscript.
Create a data grid (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=< Span class= "ATV" > " > product id</TH>
  8. <th field = "ListPrice" width=< Span class= "ATV" > " align= "right" formatter= "Formatprice" >list price</TH>
  9. <th field="UnitCost" width= "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, which is used to indicate the format function.

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

Easyui Formatting columns

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.