如何动态地更改ExtJS上的getRowClass函数GridPanel viewconfig在渲染之后 [英] How to Dynamically Change the getRowClass function on an ExtJS GridPanel viewconfig After Render

查看:822
本文介绍了如何动态地更改ExtJS上的getRowClass函数GridPanel viewconfig在渲染之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Ext.grid.Panel ,其中一个函数返回一个自定义类,用于通过覆盖getRowClass函数对网格中的代码行进行着色。这很好,但是我想给用户更改网格着色的条件的选项。在下面的例子中,我用severity属性着色,但是我想将其改为status。有没有办法,我可以动态地更改 getRowClass 函数,或者可能是网格上的整个viewconfig,并且在网格已经呈现之后有网格recolor? p>

I have an Ext.grid.Panel with a function that returns a custom class that is used to color code rows in the grid by overriding the getRowClass function. This works great, but I would like to give the user the option to change the criteria by which the grid is colored. The below example, I am coloring by the "severity" attribute, but I would like to change that to "status", for example. Is there a way I can dynamically change the getRowClass function, or maybe the entire viewconfig on the grid, and have the grid recolor, after the grid has already been rendered?

alarmsGrid = Ext.create('Ext.grid.Panel', {
    title: 'Netcool Alarms',
    id: 'Netcool Alarms',
    columnLines: true,
    store: alarms_store,
    loadMask: true,
    stripeRows: true,
    features: [alarmsGroupingFeature],
    viewConfig: {
        getRowClass: function(record, rowIndex, rowParams, store){
          return record.get('severity').toLowerCase();
        }
    },


推荐答案

这只是因为你在做这是错误的方式,几乎所有类型的配置对象只能在类的实例化时间相关,后来不会有任何影响,所以你需要获得视图实例,直接改变支路为了从你的评论中拿出你的例子,你需要写出它像

This is simply because you are doing it the wrong way. Nearly all sorts of config objects are only relevant at instantiation time of a class and wan't have any effect afterwards. So you need to get the view instance itself to directly change the property (method) there. To take your example from the comment you will need to write it like

alarmsGrid.getView().getRowClass = function(record, rowIndex, rowParams, store){ 
     return record.get('status').toLowerCase(); 
}

请参阅 JSFiddle

See JSFiddle

这篇关于如何动态地更改ExtJS上的getRowClass函数GridPanel viewconfig在渲染之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆