Results 1 to 7 of 7

Thread: Grid set row color based on values in a column

  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    19

    Default Grid set row color based on values in a column

    I have one column in my grid for a product code. I want to highlight records that have incorrect product codes. I have created a CSS class for this. I just don't know how to set the class. In my column model, when I define this particular column, I have setup a renderer to test for the column values.
    Code:
                        {
                            header:'MPF',
                            dataIndex:'f4101_imsrp2',
                            width: 35,
                            renderer: function(value){
                                    if (value in {'C8K':'', 'C2K':''}) {
                                            return value;
                                    }
                                    else {
                                            // set class
                                            //grid.getView().getRowClass = 'error';
                                            //grid.getView().getRow(0).addClass('error');
                                            return value;
                                    }
                            }
                        },
    First of all, is this the best way to do this, that is, test for a certain value in a cell, and if it resolves false, call something to change the class for the row it's in? Secondly, how do I set the row class?

  2. #2
    Sencha User florian_cargoet's Avatar
    Join Date
    May 2009
    Location
    Paris, France
    Posts
    32

    Default

    Have you tried using viewConfig ?

    PHP Code:
    viewConfig: {
        
    getRowClass: function(recordrowIndexrpds){
            if(
    the product code is correct){
                return 
    'correct-row'
            } else {
                return 
    'incorrect-row';
            }
        }


  3. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    19

    Default

    How would I get the "value" from the variables record, rowIndex, rp, ds?

  4. #4
    Sencha User florian_cargoet's Avatar
    Join Date
    May 2009
    Location
    Paris, France
    Posts
    32

    Default

    Based on what I see in your code sample, I'd say :
    PHP Code:
    record.get('f4101_imsrp2'

  5. #5
    Sencha User
    Join Date
    Jan 2011
    Posts
    19

    Default

    Great, one last thing, I am using the (value in {}) array method, how can I do not in array?
    Code:
                    getRowClass: function(record, rowIndex, p, store) {
                            var code = record.get('f4101_imsrp2');
                            if (code in {'':'', 'C2K':'', 'C78':'', 'C8K':''}) {
                                    return '';
                            } else {
                                    return 'error';
                            }
                    },
    I tried doing if (code not in {..., but it didn't understand the "not", I also tried putting a ! before the code, to no avail.

  6. #6
    Sencha User florian_cargoet's Avatar
    Join Date
    May 2009
    Location
    Paris, France
    Posts
    32

    Default

    PHP Code:
     ! ( /* condition */ 
    Are you familiar with JavaScript? If not, you may want to get more comfortable with it before diving into Ext JS.

  7. #7
    Sencha User
    Join Date
    Jan 2011
    Posts
    19

    Default

    Thanks!

    And yes, I am familiar with it, it just escaped me to put an extra set of parens around the expression. I am new however to ExtJS (obviously). I kept thinking of the SQL expression "NOT IN ()". Anyway, thanks, I got it all working now.

Similar Threads

  1. How to set Grid row color?
    By peacock in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 17 Apr 2009, 6:18 AM
  2. set background-color to a row of a grid
    By bhanu prakash dasari in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 30 Mar 2009, 11:34 PM
  3. [Solved]change column color of single row(grid column names row)
    By amey7p in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 14 Feb 2008, 3:52 AM
  4. how to set grid, different row different color
    By ip2j in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 18 Jun 2007, 5:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •