Hey!
I started using your Tabulator some time ago for my school project and really love it. However I am still quite unsure with some of the functions and syntaxes how they work.
Currently I am struggling making a search bar for my webclient to search from my databases.
As I understood I could use the variable from my user input to make search function for the table and process it that side.
After alot of struggling and googling I came accross for a solution you had made for other person:
``
//custom filter function
function matchAny(data, filterParams){
//data - the data for the row being filtered
//filterParams - params object passed to the filter
var match = false;
for(var key in data){
if(data[key] == filterParams.value){
match = true;
}
}
console.log(match);
return match;
}
//set filter to custom function
$("#example-table").tabulator("setFilter", matchAny, {value:x});
This function actually does pretty much what I want, however it requires exact match to get the data.
I have tried different ways to change if(data[key] == filterParams.value) to make it accept "type:like" instead but have been unsuccessful.
I was wondering if this is possible to achieve with this code or do I need to scratch my plan to modify this, and return to trying to find new solution?
Thanks!
Hi @Honiah,
do you need to support filter expressions like "type:like" or do you just want a case-insensitive filter for any substring in the table?
The latter you could achieve by changing the condition to
if( data[key].toLowerCase().indexOf(filterParams.value.toLowerCase()) !== -1 )
Though I'm not sure what it does if the data[key] is a number. Might want to check for type and convert it to a string first.
Hey @Honiah
@Nyut0n has the correct approach there, that is actually how Tabulator does its inbuilt like filter.
If you want to see how ant of the inbuilt filters work for inspiration have a look at the /src/js/extensions/filter.js file, the Filter.prototype.filters object on line 525 contains all of the inbuilt filter functions.
I hope that helps,
Cheers
Oli :)
With your comments and I realised I will not get my search function to work like I want to, not likely atleast, so I decided to take different approach with my problem.
Instead of making separate call function to search I join tables with concat and use the amazing filtering that Tabulator already has to offer.
Thank you for the responses!