1

需要以 Ext.netgridPannel颜色突出显示需要突出显示的一组行

当前的方法是在渲染 GridPannel 时调用以下函数:

 function (value, meta, record, rowIndex,columnIndex,store) 
    {

                    color= record.data["ColorValue"];
                    var style = document.createElement('style');
                    style.type = 'text/css';
                    style.innerHTML = '.cssClass'+rowIndex+' {   background color:'+color+'}';
                    document.getElementsByTagName('head')[0].appendChild(style);
                    grid.store.getAt(rowIndex).set("mySelected", "cssClass"+rowIndex);
    }

但是使用这种方法:它突出显示具有相同颜色的所有行.. 测试alert(color);从 GridPannel 获取每种颜色的正确不同颜色

有什么好的方法吗?

4

2 回答 2

1

您可以覆盖 GridView 中的 getRowClass 方法。

new Ext.grid.GridPanel({
    [...],
    viewConfig: {
        getRowClass: function(record, index, rowParams, store) { return 'some-class'; }
    }
});

或者,如果您需要在渲染后应用颜色,您可以尝试为每一行设置:

grid.getView().getRow(0).className += 'some-class';

注意:这个示例基于 ExtJS 3.4 API,但我敢打赌 4.0 中会有类似的东西。

于 2011-11-25T06:47:47.703 回答
0

使用 ExtJS 4,您可以使用网格存储中记录的行元素的highlight方法。

var store = grid.getStore();
var view  = grid.getView();
var node;

store.each(function(record) {
    if (record.get('fieldname') !== 'your_condition') return;

    //Return the node given the passed Record, or index or node.
    node = view.getNode(record);
    if (!node) return;

    Ext.get(node).highlight();
});
于 2015-10-16T08:48:31.350 回答