简体   繁体   English

覆盖JavaScript函数ag-grid

[英]Overwrite javascript function ag-grid

there is a functionality that i need to change in ag-grid, and for this i need to change a function, for example from: 我需要在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();
            }
        };

To

 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();
            }
        };

How can i overwrite the functionality in th ag-grid configuration file? 如何覆盖农业网格配置文件中的功能? Above i leave a demo example with the configuration file: 我在上面留下了一个带有配置文件的演示示例:

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

Duplicate here : Ag-grid inheritate functionality 复制此处: Ag-grid继承功能

I'm reposting my answer from there 我从那里重新发布我的答案


You should use Javascript inheritance on NumberFilter and then overtwrite the method onFilterChanged. 您应该在NumberFilter上使用Javascript继承,然后覆盖onFilterChanged方法。 Check this answer to see how to do it : JavaScript override methods 检查此答案以查看如何做: JavaScript覆盖方法

Then instead of specifying 然后,而不是指定

filter:'number'

You can do : 你可以做 :

filter:new MyNumberFilter();

As you can see i instanciated the filter, it's required or you will have the same instance for all your number column's filter on the grid. 如您所见,我实例化了过滤器,这是必需的,否则您在网格上所有数字列的过滤器将具有相同的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM