ExtJS change Gridpanel cell background color or set whole line font color based on value

Source: Internet
Author: User

The first step. Set style

. reportcolor4{
Background: #93A9C1;
}
. reportcolor5{
Background: #EEEEEE;
}

Step two. Modify cell styles

Header: ' Flow type ',
WIDTH:80,
Sortable:true,
Align: ' center ',
Dataindex: ' Br_type ',
CSS: ' background: #acdaf4; ',//-----To set the style of the entire cell, but it cannot be changed according to the condition
Renderer:function (V,cellmeta) {
if (v==1) {//Judgment value type
Cellmeta.css= "ReportColor4"; Set style
Return "<span style= ' color:white ' > Lending </span>"; Change the output font color
}else if (v==2) {
Cellmeta.css= "ReportColor5";
Return "<span style= ' Color:green ' > Return </span>";
}else{
Return "<span style= ' Color:blue ' > Unknown </span>";
}
}

Step two. Modify the entire row color

Eradicate value value modifies the color of the entire row, which needs to be configured in the viewconfig of the grid

Viewconfig: {forcefit:true,
Getrowclass:function (Record,index,p,ds) {
var cls = ' White-row ';
Switch (Record.data.STATUS) {
Case ' 0 ': cls = ' X-grid-record-green '; Break
Case ' 1 ': cls = ' X-grid-record-yellow '; Break
Case ' 2 ': cls = ' X-grid-record-orange '; Break
Case ' 3 ': cls = ' x-grid-record-red '; Break
Case ' 4 ': cls = ' X-grid-record-gray '; Break
}
return CLS;
}
}

Of course, font styles also need to be defined

. X-grid-record-gray table{color: #948d8e;}
. x-grid-record-red table{color:red;}
. X-grid-record-yellow table{Color:blue;}
. X-grid-record-green table{Color:green;}
. X-grid-record-orange table{Color:orange;}

========= Notes =================

renderer method is very common, first look at the parameters in the Renderer:function ()

Renderer:function (value, Cellmeta, record, RowIndex, ColumnIndex, store) {

}
1.value is the value of the current cell
2.cellmeta saved is Cellid cell id,id do not know what to do, it seems to be a column number, CSS is the CSS style of this cell.
3.record is all the data in this line, what you want, record.data["id") so you get it.
4.rowIndex is the line number, not the meaning of the number from the beginning, but the calculation of the results after paging.
The 5.columnIndex column number is too simple.
6.store, this is very powerful, actually this is the time you construct the form to pass the DS, that is, all the data in the table, you can call, alas, too powerful.

ExtJS change Gridpanel cell background color or set whole line font color based on value

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.