How to replace " | " with a " , " in the regex search?
How to replace " | " with a " , " in the regex search?

Hi,
First of all, I would like to appreciate the whole team's effort. Secondly, I am using regex on global search which is working fine. So the problem I'm facing is that by default we have to type multiple values in the search input field like this Tokyo|London|San Francisco which I don't want. What I want is to replace " | " with " , " in the search input field. For instance: Tokyo, London, San Francisco and do the same work. I hope you guys get my point. Have a nice day.
This question has an accepted answers - jump to answer
Answers
Hi @Moiz ,
Thanks for the kind words.
That's not a valid regex, so you'll need to convert the commas to bars first (
replace(/,/g, '|')
). Probably the easiest way would be to repurpose the existing searchinput
, as shown in this example.Cheers,
Colin
Thanks for helping me out brother @colin! I have implemented this in my project and it works like a charm but the problem I'm facing right now is that after searching multiple values when I click on arrows for sorting, it changes back the string of search input field to the default format which I don't want. For instance: Tokyo|London|New York
This is the code I have added.
$('.dataTables_filter input').on( 'keyup click', function () {
} );
Hi @Moiz ,
Could you update my test case to demonstrate that, please.
Cheers,
Colin
I would expect that to happen. If you don't want that then you will need to create your own search input and use the
dom
option to remove the default search input.Kevin
There you go, brother.
http://live.datatables.net/kupegudi/5/edit
Ah, yep, as Kevin said. The change of order causes a draw which means the search term (with the bars) is pushed into the input element. If you use your own input element as Kevin said, this wont happen. Apologies for the confusion.
Hmm. Okay, brother Kevin, I will also try that and give you my feedback.
Nah! Don't Apologize to me brother @colin. Again thanks for helping me out both of you. Cheers