7

I want to get the value of another column in the same row, in a renderer function of one column. I tried a method, but it didn't work. And here's my code:

columns: [
            {id:'id',header: 'ID', width: 30, sortable: true, dataIndex: 'category_id'},

            {header: 'current_level', width: 100, sortable: true, dataIndex: 'current_level'},
            {header: 'complete_code', width: 100, sortable: true, dataIndex: 'complete_code'},
            {header: 'parent_id', width: 100, sortable: true, dataIndex: 'parent_id'},
            {header: 'parent_name', width: 100, sortable: true, dataIndex: 'parent_name'},
            {
                header: 'has_standards', width: 100, sortable: true, dataIndex: 'has_standards',
                renderer: function(val, meta, record, rowIndex) {
                    if (val == 'Yes') {
                        console.log(record.data.category_id);
                    }
                }
            }
        ],

As you see, I want to get the category_id in the same row, in the renderer function of has_standards column. But my way is wrong. Could you tell me how to do it?

Mingrui Ji
  • 399
  • 2
  • 6
  • 11
  • `record.data.category_id` is correct. What is wrong? Is there any error? Is `val == 'Yes'` correct? Can you post more code? – Shlomo Nov 11 '13 at 13:11

2 Answers2

14

You want to use record.get('category_id') e.g.:

           renderer: function(val, meta, record, rowIndex) {
                if (val === 'Yes') {
                    console.log(record.get('category_id'));
                }else{
                    console.log('Value is not "Yes"');
                }
            }
SW4
  • 69,876
  • 20
  • 132
  • 137
0

I am using Ext JS 6 (Sencha) and I wanted to display an image in a grid column based on whether the value of another column in the same grid was of a certain value. I followed SW4's solution with some minor changes as per the version of Ext JS I am using and it worked great. Thank you.

Ext.define('ViewLL.view.main.List', {
extend: 'Ext.grid.Panel',
xtype: 'list',

requires: ['App.store.Datastore'],

store:  {type: 'datastore'},

columns: [
        { text: 'Market',
          renderer: function(value, metaData, record, rowIndex) {
           var value = record.get('location');
           if (value == NYC) {
           return '<img src="resources/images/bigApple.jpg"/>';
           }
           else {
           return null;
           }
          }
       },
       { text: 'City', dataIndex: 'location' }
        ]

This displays the image file in a grid column when the City column's has a record, the value of which is NYC. For all other records it displays a blank cell.

Forcom
  • 1