Results 1 to 3 of 3

Thread: Any way to Render a Grid Item based on another column value?

  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2010
    Posts
    82

    Default Any way to Render a Grid Item based on another column value?

    Hello,

    I'm trying to follow this example where the array grid item uses renderer to make it red or green based on the item value:
    http://dev.sencha.com/deploy/dev/exa...rray-grid.html

    This is the function that makes the change:
    Code:
    function change(val) {
            if (val > 0) {
                return '<span style="color:green;">' + val + '</span>';
            } else if (val < 0) {
                return '<span style="color:red;">' + val + '</span>';
            }
            return val;       }
    And the rendere is used here in the column model:
    Code:
    {
                    header   : 'Change', 
                    width    : 75, 
                    sortable : true, 
                    renderer : change, 
                    dataIndex: 'change'}
    Is there a way to pass another item for "val"? For example I have a column 'Change 2', and depending on the value of that column I want to use a renderer to make 'Change' column red.

    Hope this makes sense.

  2. #2
    Sencha Developer
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,516

    Default

    Look at the API docs for Column:
    - http://dev.sencha.com/deploy/dev/doc...xt.grid.Column

    Scroll down to the renderer property.

    PHP Code:
    renderer: function renderer(valmetaDatarecordrowIndexcolIndexstore) {
        
    //your logic here

    Use "record.get('someVal')" to access the other fields on your record.

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Location
    Dublin
    Posts
    72

    Default

    It works for me.

    I just changed the style of a cell depending on the value, just adding value instead of val (in Sencha Architect) with the style works. Thank you for the advice about the styling.

    Regards

    Quote Originally Posted by arthurakay View Post
    Look at the API docs for Column:
    - http://dev.sencha.com/deploy/dev/doc...xt.grid.Column

    Scroll down to the renderer property.

    PHP Code:
    renderer: function renderer(valmetaDatarecordrowIndexcolIndexstore) {
        
    //your logic here

    Use "record.get('someVal')" to access the other fields on your record.

Similar Threads

  1. ColumnTree render column based on containersize
    By jbird526 in forum Community Discussion
    Replies: 5
    Last Post: 22 Jul 2009, 6:20 AM
  2. CheckBox in column for a grid based on the value of the column
    By prext in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 3 Dec 2008, 11:01 PM
  3. render checkbox for each column based on response xml
    By kckc1234 in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 15 Sep 2008, 4:52 AM
  4. Replies: 1
    Last Post: 10 Sep 2008, 3:51 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
  •