How to get value of other column in renderer function in Extjs?
Asked Answered
S

2

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?

Sandal answered 11/11, 2013 at 13:0 Comment(1)
record.data.category_id is correct. What is wrong? Is there any error? Is val == 'Yes' correct? Can you post more code?Lefebvre
I
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"');
                }
            }
Invitation answered 11/11, 2013 at 13:13 Comment(0)
A
1

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.

Albertson answered 16/11, 2015 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.