Hello,
I’m currently trying to integrate a custom filter function to handle numeric filtering.
The default #numeric_filter tool is not working - most likely do to some customization other developers on my team did to the library. FYI, we are using an older version of DHTMLX (3.5). Note, using this older version does not affect the usability of the grid.
The interesting part:
I’ll first show you the method that I’ve written to handle numeric filtering. Then I’ll describe the issues I am having.
Note - gridtable is the name of my grid.
Note - The input field has been created using attacheHeader method and including #numeric_filter. That being said, I am accessing the input an trying to write my own function. I am considering that this might be a source of the issue, but since the function is custom, I do not think this is the source of the issue.********
What the function is doing - it should take the input in the first column and perform the filter function on it.
gridtable.getFilterElement(0)._filter = function(){
var input = this.value; // gets the text of the filter input
let operator = input.match(/>=|<=|>|</);
var number = input.match(/\d+/g);
// If operator is null and there is a number, return the number
if (!operator && number) {
gridtable.filterBy(0,function(a){ return (a == number);}, true);
}
if (operator) operator = operator[0];
number = parseInt(number);
if (operator && number) {
switch(operator) {
case ">=":
gridtable.filterBy(0,function(a){ return (a>=number);}, true);
break
case "<=":
gridtable.filterBy(0,function(a){ return (a<=number);}, true);
break
case ">":
gridtable.filterBy(0,function(a){ return (a>number);}, true);
break
case "<":
gridtable.filterBy(0,function(a){ return (a<number);}, true);
break
}
}
return
}
Issues I am having:
Problem 1. Just including this function does not cause the filter function to occur when a user enters a value. I need to include an empty event handler above it. It is not clear to me why this is needed to yield a result, considering that the event handler function is empty.
gridtable.attachEvent("onFilterStart", function(ind, val) {
});
Once the above event handler has been included, I am able to return a first result - for example, if the grid has 50 rows and numbers 1-50 in the cells, and my input is ‘>10’, the grid will yield 11-50. This works, but then:
Problem 2:
If I then try clear the field to show all results again - it is not clear to me how to do that. I tried using the ‘onFilterEnd’ event handler, but it doesn’t fire when I empty the field.
Problem 3:
If I try to search for an item in the grid which is 10 or less, I get the error “Cannot read properties of undefined (reading ‘idd’)”. Tracing this error down takes me to the library code, which from my understanding should not be an issue since I am writing a custom function - not using the #numeric_filter filtering method. Recall the note from above (***********). Might this still be calling the library, even if there is a custom function written?
I’ve written the following function to handle numeric filtering
Problem 4:
It is not clear to me how combo filtering is meant to work. You’ll notice in the code above, I added a 3rd parameter (true) [ gridtable.filterBy(0,function(a){ return (a>=number);}, true);] My understanding is that adding true to a filterBy method allows combo filtering to work - though I admit it is not clear to me how.
Any support is welcome, thank you.