Filter/Search: 'Begins With' instead of 'Contains'

When we enable the Filter or Search criteria for DhtmlX Grid it performs a search based on ‘Contains’. Can we configure it to use ‘Begins With’.

I am using this grid to show the list of Accounts where for ‘Account Code’ column users like to apply filters as show all the accounts starting with ‘4’. In this situation the default search criteria returns all the rows where ‘4’ appears anywhere in the code instead of the records where code is beginning with ‘4’.

Any assistance is highly appreciated.

It can be easily changed in source code, but if you preffer noninvasive way - the next can be used

grid.getFilterElement(index)._filter = function(){ var value = this.value; //actual value of input return function(data){ // filtering method if (this.value.indexOf(data) == 0) return true; //begins with return false; } };

Thanks for the reply.

Can you please guide me where to place this code? I am getting ‘index’ is undefined JavaScript error.

Code need to be placed after grid initialization ( when filters already has been created )
Change “index” to the index of the column, in which filter need to be altered.


i´ve the same issue - but i can´t get them to work.

I´ve placed the code behind
and have changed the index to 7 because it´s the eight column i want to assign these filter

but i always get the error

‘this.value’ is null or not an object

What´s wrong? Can you help please?

Above code will work only for built-in filters, such as #text_filter, #select_filter. It will not work for custom or any other types of built-in filters.

Also, be sure that your code is called, when extra header line, with filters, is already defined.