Filters to Grid

Hello,

i have a grid with filters like in this example :
http://docs.dhtmlx.com/tutorials__first_app__step7.html

But i want to know if it possible to have a filter like :

If i type “AH”, i want to see in the data, the results which began with “AH”.
And how to make it possible if the filter have this possibility ?

Must i write some special character like :

Filters
“%AQ%” ==> words with “AQ” in the middle.
Or “%AQ” ==>words which finish with “AQ” etc

I didn’t find anything in the docs.
Thanks.

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.

Thanks for your help :slight_smile:

I finally found a solution and it works.

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 } }