Any filter you assign to the grid (both by adding it to the header and by creating through the makeFilter() function) can use a custom logic instead of the default one.
To change the filtering logic of a filter assigned to the grid, you should redefine its _filter function like in:
grid.getFilterElement(col_index)._filter = function(){
//you custom logic
}
For example, you can use the following definition to create a filter (based on text_filter) that searches the result in all columns of the grid:
mygrid.getFilterElement(0)._filter = function(){
var input = this.value; // gets the text of the filter input
return function(value, id){
for(var i=0;i<mygrid.getColumnsNum();i++){ // iterating through the columns
var val=mygrid.cells(id,i).getValue() // gets the value of the current cell
if (val.toLowerCase().indexOf(input.toLowerCase())!==-1){ // checks if the value of a cell have the text from the filter
return true
}
}
return false
}
}
Thank you sematik but i don’t know where am i supposed to write this code…
I wrote like this :
var mygrid;
function doInitGrid(){
[...]
mygrid.attachHeader("#text_filter,#numeric_filter,#text_filter");
mygrid.getFilterElement(0)._filter = function(){
var input = this.value; // gets the text of the filter input
return function(value, id){
for(var i=0;i<mygrid.getColumnsNum();i++){ // iterating through the columns
var val=mygrid.cells(id,i).getValue() // gets the value of the current cell
if (val.toLowerCase().indexOf(input.toLowerCase())!==-1){ // checks if the value of a cell have the text from the filter
return true
}
}
[...]}
This code doesn’t compile and my grid is not shown.
In my example, i want to filter the first column with this special filter.
If i write “12”, i want to see only the product which begin with “12” not the products which have “12” in their number.
If somebody needs it, here is the code : index.html
mygrid.load("php/data.php");
mygrid.getFilterElement(0)._filter = function(){
var input = this.value; // gets the text of the filter input
return function(value, id){
var myRegex = new RegExp("^"+input, "gi")
if (myRegex.test(value) == true)
return true;
else
return false
}
}
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan