ExtJS不使用我的网格过滤器覆盖

ExtJS is not using my grid filter override

本文关键字:网格 过滤器 覆盖 我的 ExtJS      更新时间:2023-09-26

我有一个项目,我需要做一个自定义网格日期过滤器。

在有状态保存之前一切正常。我需要为状态添加一个自定义值。我从扩展Ext.util.Filter的类重写了getState方法:

Ext.define('RelativeDateUtilFilter', {
extend: 'Ext.util.Filter',

getState: function () {
    var config = this.getInitialConfig(),
        result = {},
        name;

    for (name in config) {
        if (config.hasOwnProperty(name)) {
            result[name] = config[name];
        }
    }

    delete result.root;
    result.value = this.getValue();
    //this is the line I added
    result.relValue = this.relValue;

    this.callParent();

    return result;
}
});

我有一个过滤器基类的重写,使它使用我自己的util过滤器:

createFilter: function (config, key) {
        var filter = new RelativeDateUtilFilter(this.getFilterConfig(config, key));
        filter.isGridFilter = true;
        return filter;
    }

问题是,RelativeDateUtilFilter类中的getState仅在我第一次创建过滤器时被调用。当ExtJS保存状态时,它使用基类Ext.util.Filter中的状态。
我可以通过将我的代码直接放在Ext.util.Filter类中来解决问题,但我不想这样做,因为它在我想升级的情况下不好。

简而言之,在编写状态时如何强制ExtJS使用我自己的getState方法?

任何帮助都是感激的!

<标题>编辑:

如果这对某人有帮助,我通过删除我的RelativeDateUtilFilter类和我的过滤基础覆盖来修复这个问题,并将我的getState方法放在覆盖文件中:

Ext.define('Override.util.Filter', {
    override :'Ext.util.Filter',
    getState: function () {
        var config = this.getInitialConfig(),
            result = {},
            name;
        for (name in config) {
            // We only want the instance properties in this case, not inherited ones,
            // so we need hasOwnProperty to filter out our class values.
            if (config.hasOwnProperty(name)) {
                result[name] = config[name];
            }
        }
        delete result.root;
        result.value = this.getValue();
        if(this.relValue) {
            result.relValue = this.relValue;
        }
        return result;
    }
});

(在/覆盖/util/Filter,js文件中,所以它被SenchaCMD正确加载)

再次感谢@子弹列车!

我相信在您的情况下,您不需要this.callParent();作为重写方法的一部分,这里有一个关于重写方法的不同方法的很好的解释https://sencha.guru/2015/01/20/overriding-methods-safely/