Logical OR and First letter
Logical OR and First letter

Hello everyone,
First of all, thank for datatable, it's awesome !
I would like to use search by first letter and searching by first letter.
What I already did is that :
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search('\b'+this.value, true, false )
.draw();
}
} );
which allow me to search by first letter.
The problem is, if I want to use the logical OR (while adding |) the second item isn't searched by first letter.
I tried to split("|") and reconstruct my string in a loop and then search(string) but it doesn't work.
Do I do something wrong ?
Answers
You probably aren't building the correct regex expression. You can use regex101 to build the needed expression. I think you might need two backslashes in front of the
b
and your OR terms probably need to be in square brackets ([]
). Something like this"\\b[a|b]"
.If you still need help please build a test case so we can help debug your code.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you for your answer.
There was two backslashes the first was ignored in the text.
It wasn't square brackets but parenthesis what I needed. Now it works thanks to your answer.
Final code :
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search('\\b('+this.value+')', true, false )
.draw();
}
} );