We have a grid with a column that contains values that are the same except for case, e.g.,
abc,
Abc,
aBc,
abC
In our grid, this column has a select filter which contains a drop down list element for each of the case sensitive elements. However, since the filtering is case insensitive, selecting any of those elements returns the matching rows for all of them. We like the case insensitive filtering and would like to prune the filter list so that only a lower case version of each value appears in the drop down list. I’ve tried to modify the list in the “onCollectValues” callback, but at that time, the filter element returned by getFilterElement has not been populated, so I don’t have any source values to work with. Is there a way to achieve the filtering of elements in the drop down list after the values have been collected?
Thanks for your consideration.
Steve
You may redefine the logic of the filter. Here you can find an example of the logic:
https://docs.dhtmlx.com/grid__filtering.html#redefiningdefaultfilterlogic
Or you may add the following custom filter:
dhtmlXGridObject.prototype._in_header_select_filter_case=function(t,i){
t.innerHTML="<select style='width:90%;'></select>";
t.onclick=function(e){ (e||event).cancelBubble=true; return false; }
this.makeFilter(t.firstChild,i);
var combos = this.combos;
t.firstChild._filter=function(){
var value = t.firstChild.value;
if (!value) return "";
if (combos[i])
value = combos[i].keys[combos[i].values._dhx_find(value)];
return function(val){
return (val.toString()==value);
};
};
this._filters_ready();
}
just try to use #select_filter_case
in your grid configuration.
Thanks for the reply. However, the solutions you provide change the way the filtering works, e.g., the custom filter code above will filter in a case-sensitive manner, and not the way the list of elements in the filter drop down list are generated. I want to preserve the case insensitive filtering, but I want the list of filter choices in the drop down list to only contain one choice (probably lower case version) for each element. In my original example of column data containing
abc
Abc
aBc
abC
I’d like the filter drop down list to contain only
abc
and selecting this element will match columns that contain any of abc, Abc, aBc, abC. Currently all 4 values are put into the drop down list and using “select_filter” matches all the rows containing abc regardless of case.
If I add the select_filter_case as above, the drop down list still contains all the case variant elements, but the filtering only matches the rows with an exact case match.
I thought the onCollectValues event would be the appropriate place to make the list elements unique, but the filter element hasn’t been populated when this event is triggered, so I’d have to iterate all the data to create the list from scratch (not an optimal solution).
Thanks,
Steve
I apologize. Now I see the request. Unfortunately it is not available to change the options in the list to lower case. without inner code modifications.
Only the “onCollectValues” event (as you’ve mentioned) can be used, but it requires to modify all the filtering process.