0

I have a Grid-Panel with a few columns. Now I want to set a new Class in a Column of a Row, when the values don't match with each other. But how can i get success to a column in a different row? Her is my code which I tried, but it says, the ID is undefined:

...{
    header: 'CRS',  
    dataIndex: 'crs',
    id:'crs',
    flex:1,
    renderer: function(value, meta) {

        console.log("csv-->"+Ext.getCmp('csv').value);

        if(value==Ext.getCmp('csv').value)
            {
                //change class
            }

    }
},
{
    header: 'CSV', 
    dataIndex: 'csv',
    id:'csv',
    flex:1
},...
4

3 回答 3

2

The code you've posted does not seem to match what you're asking for. According to your code, it appears that you're trying to compare values across columns in the same row, not a different row. So which is it?

Anyway, assuming that your code is indicative of what you want, be sure to look at the docs for the the renderer: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.grid.column.Column-cfg-renderer

One of the arguments passed to the renderer method is the "record", which will contain all the values for the record which is filling the values for the entire row. If you wanted to compare values across columns, you could do something like:

if( value==record.get( 'csv ') ) { 
    ...do something here... 
}

If you really need to compare values across rows, then the "store" also gets passed as one of the arguments to renderer, so you could compare values against specific row values that way.

Alternatively, you could do most of this in Model itself. If you are just comparing columns in the same row, you could create an additional field in your Model that stores the result of the comparison. If you did that, all that your renderer would need to do is switch on the value of that new field, rather than doing the entire comparison AND rendering.

于 2013-09-05T11:27:16.167 回答
1

我有!这对我有用:

{
    header: 'CSV', 
    dataIndex: 'csv',
    flex:1,
    renderer: function(grid, rowIndex, rowdata) {
        var csv_data=rowdata.data.csv;
        var crs_data=rowdata.data.crs;
        if (csv_data != crs_data) { 
           rowIndex.tdCls = "red-class";
        } 
            return csv_data;

    }
},
于 2013-09-05T12:37:29.893 回答
0
{
    header: 'CSV', 
    dataIndex: 'csv',
    flex:1,
    renderer: function(value, meta, record) {
        var crs = record.get('crs');
        if (value && crs)
        {
            if (value != crs) { 
               meta.tdCls = "red-class";
            }
        }
        return value;
    }
},

为 ExtJS 4 重写,你可以使用你在 dataIndex 中设置的值,因为这是一个记录,推荐的 extjs 4 获取值的方法是 get 方法。

只是提醒一下,渲染器还有很多属性,您可以在此处找到完整列表:http: //docs.sencha.com/extjs/4.2.2/#! /api/Ext.grid.column.Column- cfg 渲染器

于 2014-05-20T17:02:48.337 回答