Datatables search deal with a letter as another letter
Datatables search deal with a letter as another letter
I have this example http://live.datatables.net/mimovodu/1/edit
I need to search أحمد as احمد in Arabic, that means I need this letter ا act as this letter أ in Arabic.
Another example for English, the letter e act as i when searching if I have two words in the table for example: ice and english. If I typed the letter i in the search bar it will show both words ice and english. How can I do this?
This question has accepted answers - jump to:
Answers
You would use Orthogonal data for this. Use
columns.render
to replace the desired letters for thefilter
operation. Here is a simple example:http://live.datatables.net/hejimuke/1/edit
Kevin
@kthorngren Yeah your answer worked perfectly in the example, but I need to do that with Arabic language ... It doesn't let me type Arabic letters with
/
probably inreturn data.replace
, any solutions?The return is using Javascript replace(). Maybe this SO thread will help. See this updated example based on your first description:
http://live.datatables.net/hejimuke/3/edit
If this doesn't help then search Stack Overflow for how to handle the Arabic language with the regex replace. The
return data.replace(/احمد/gi, 'أحمد');
is standard Javascript and not influenced by Datatables.Kevin
@kthorngren Strange, I did the exact same code that you did without Arabic words just to test if it works in my website + some language stuff but it is not working in my website but it works in live.datatables.net! http://live.datatables.net/hejimuke/9/edit?html,css,js,console,output
How could that be possible? Why the EXACT code not working in my website? Also, there are no errors everything works fine even the search and language works fine, but the data.replace thing is not working...
If you are using
columnDefs
, like the test cases, make sure yourcolumnDefs.targets
is the correct column. The column numbers start counting from0
. You can also try the .replace() with thereturn data;
at the end of the function to see what the data looks like.In order to help debug we will need to see the problem. Please provide a link to your page or update the test case to replicate the issue.
Kevin
@kthorngren 1st problem is that my web application is localhost ... 2nd problem that I am not that good with JavaScript. Furthermore, what do you mean by "make sure your columnDefs.targets is the correct column."? Regarding
.replace()
with thereturn data;
at the end of the function, you mean I should do thisreturn replace();
? Maybe examples? Also maybe if you could help me privately because the problem still exists ... Thanks for your helping.columnDefs.targets
indicates which column the rules apply to, and as Kevin said, they're UNIX-style numbering so start from 0.But yep, we would need to see the problem to progress this efficiently - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I meant to use the same return statement as in the if statement, for example:
The developers have various support plans that can be purchased for private help. Click the
Ask a Private Question
to make arrangements with Allan.Kevin
@kthorngren Ok, I posted my whole code in this live.datatables link http://live.datatables.net/labifadu/1/edit?html,js,output and yeah it is not working! Could you please test it for me, and see what is wrong? This is working http://live.datatables.net/hejimuke/9/edit but this http://live.datatables.net/labifadu/1/edit?html,js,output is not working! So, there is a problem definitely in my code! Can you please check it out?
As I mentioned you need to make sure the
columnDefs.targets
points to the correct column. The column numbers start counting at 0 so the column you want to change is 3. Please see thecolumnDefs.targets
docs for more details. Here is the updated example:http://live.datatables.net/labifadu/2/edit
Kevin
@kthorngren Thanks! It worked! Thank you so much for your support! Also thanks for @colin for the support!