覆盖javascript函数ag-grid

时间:2016-03-05 11:14:27

标签: javascript ag-grid

我需要在ag-grid中更改一个功能,为此我需要更改一个功能,例如:

 NumberFilter.prototype.onFilterChanged = function () {

            var filterText = utils_1.default.makeNull(this.eFilterTextField.value);

            if (filterText && filterText.trim() === '') {
                filterText = null;
            }
            var newFilter;
            if (filterText !== null && filterText !== undefined) {

            console.log(filterText);


                newFilter = parseFloat(filterText);
                console.log(newFilter);
            }
            else {
                newFilter = null;
            }
            if (this.filterNumber !== newFilter) {
                this.filterNumber = newFilter;
                this.filterChanged();
            }
        };

 NumberFilter.prototype.onFilterChanged = function () {

            var filterText = utils_1.default.makeNull(this.eFilterTextField.value);

            if (filterText && filterText.trim() === '') {
                filterText = null;
            }
            var newFilter;
            if (filterText !== null && filterText !== undefined) {

            console.log(filterText);

                // replace comma by dot
                newFilter = parseFloat(filterText.replace(/,/g, '.'));
                console.log(newFilter);
            }
            else {
                newFilter = null;
            }
            if (this.filterNumber !== newFilter) {
                this.filterNumber = newFilter;
                this.filterChanged();
            }
        };

如何覆盖ag-grid配置文件中的功能? 上面我留下一个配置文件的演示示例:

Link: https://plnkr.co/edit/LDdrRbANSalvb4Iwh5mp?p=preview

1 个答案:

答案 0 :(得分:1)

此处复制:Ag-grid inheritate functionality

我从那里重新发布我的答案

您应该在NumberFilter上使用Javascript继承,然后覆盖onFilterChanged方法。请查看此答案,了解如何操作:JavaScript override methods

然后而不是指定

filter:'number'

你可以这样做:

filter:new MyNumberFilter();

正如您所见,我实现了过滤器,它是必需的,或者您将为网格上的所有数字列过滤器提供相同的实例。