0

there is a functionality that i need to change in ag-grid, and for this i need to change a function, for example from:

 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
Pedro
  • 1,459
  • 6
  • 22
  • 40
  • Replacing commas with dots is not a good enough reason to override the internal functions of the grid. Have you tried creating a custom filter that can deal with your number format, as described in the docs? – Tomalak Mar 05 '16 at 11:29
  • @Tomalak and reading the documentation for a small change i need to basically apply all the functionality from the NumberFilter class, so i wonder if there is a way to inherit all his functionality in a new Object and then change his method. I try do for example var CustomNumberFilter = Object.create(NumberFilter); , but doesnt work. – Pedro Mar 05 '16 at 14:51

1 Answers1

1

Duplicate here : Ag-grid inheritate functionality

I'm reposting my answer from there


You should use Javascript inheritance on NumberFilter and then overtwrite the method onFilterChanged. Check this answer to see how to do it : JavaScript override methods

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.

Community
  • 1
  • 1
Walfrat
  • 5,363
  • 1
  • 16
  • 35