Custom Filter to search at the beginning of each Word
Custom Filter to search at the beginning of each Word
Hello everyone, in the past years i used religiously dataTables for several projects, but recently i came across a though problem, as i can't get to work a custom filter to filter the table the way i want it.
To put it simply, let's assume my table is something like :
Apple
Pineapple
Paprika
Using the regular filter, typing "Ap" would select every rows, because all entries contain "Ap" somwhere. And obviously i wanted it just to retrieve "Apple".
I read A LOT of topics around this idea, and none of them could lead to a working filter system. I assume i am not the only one so we might as well get it working for future questions.
Here is what i tried so far : (as explained here : http://82.113.152.82/forums/discussion/255/customising-the-way-the-filter-works/p1
Custom input with my_search_bar id, which trigger with jQuery the fnFilter API. I read that i need to use regular expression but i can't get any result to work.
[code]$("#my_search_bar").keyup(function() {
oTable.fnFilter('/\b'+this.value,null,false,false);
});
[/code]
I also tried the second version (who is suppose to work according to Tom Clark), but it doesn't work either :
I tried changing the source of jquery.dataTables.js but i might be a bit too unexperienced with jquery and javascript in general to make it to mark.
Any leads would be greatly appreciated.
Thanks a lot,
Flavio
To put it simply, let's assume my table is something like :
Apple
Pineapple
Paprika
Using the regular filter, typing "Ap" would select every rows, because all entries contain "Ap" somwhere. And obviously i wanted it just to retrieve "Apple".
I read A LOT of topics around this idea, and none of them could lead to a working filter system. I assume i am not the only one so we might as well get it working for future questions.
Here is what i tried so far : (as explained here : http://82.113.152.82/forums/discussion/255/customising-the-way-the-filter-works/p1
Custom input with my_search_bar id, which trigger with jQuery the fnFilter API. I read that i need to use regular expression but i can't get any result to work.
[code]$("#my_search_bar").keyup(function() {
oTable.fnFilter('/\b'+this.value,null,false,false);
});
[/code]
I also tried the second version (who is suppose to work according to Tom Clark), but it doesn't work either :
I tried changing the source of jquery.dataTables.js but i might be a bit too unexperienced with jquery and javascript in general to make it to mark.
Any leads would be greatly appreciated.
Thanks a lot,
Flavio
This discussion has been closed.
Replies
Same problem remains, i should add that i tried most techniques provided in the threads mentionned.
That includes
1) different forms of regex in the fnFilter first parameter
2) i tried disabling both or once of bSmart and bRegex parameters in the source AND in the fnFilter API
3) i tried Tom Clark code, even if i did not understand much of it, the result was not satisfaying. I tried changing it around but nope.
4) allan mentionned a "key line" in the source, which should greatly help to accomplish what i want,
[code]var sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';[/code]
Unfortunately, i have no idea of what i have to do. I tried differents things as well, with no result
Thanks for any help you could give me,
Flavio
In the server_processing.php file, there is lines for Filtering :
[code]
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i