Search start with letter
Search start with letter
geethunimesh
Posts: 25Questions: 9Answers: 0
Is it possible to filter rows with start with letter?
I tried it with regex
table.search('^a', true, false).draw(); //select all rows start with a
But it only works for first column
Please help me to find a solution
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Try:
table.search('\ba', true, false).draw();
- i.e. a boundary search.That is actually something I plan to have in the next DataTables core.
Allan
That doesn't work for me allan
jsfiddle.net/ebRXw/3510/
if I use '^' it will return rows for first column search only
I think it is working now
jsfiddle.net/ebRXw/3511/
var regExSearch = '\b' + this.value;
Sorting updates search box with /b
"\b33"
Yes, that should do it. The
\b
is a boundary, which is the correct action to use rather than^
to indicate the start, since the way the search works in DataTables is to combine all the searchable columns into a single string.Allan
So Can we eliminate this "\b" on sorting?
Actually, I don't wish to appear this while sorting. Any suggestion?
I thought we were talking about search, not sort. The
\b
is a regex special character. It shouldn't effect the sort at all.Allan
@allan Now I'm manually removing "\b" while sorting. Any other better option to solve this?
I don't really understand. What has the
\b
got to do with sorting? Can you link to a test case showing the issue please? The\b
is in the filter input only - it shouldn't be in the actual data.Allan
@allan
Step to reproduce:
1. type a text in search field
2. click on any column to sort
3. check search field ['\b' will be prepended with search text]
One more issue is there
1. type "*d" in search field
2. get console error and no search will take place
Any suggestion?
You've got an internal loop there. Calling
search()
from the built in search box will cause it to update itself, which results in the search happening, which... loop.If you want to use the built in input, you'd need to unbind all of its existing listeners:
The console error is correct -
*\b
is not a valid regex.Allan