Datatables search deal with a letter as another letter

Datatables search deal with a letter as another letter

FRS4002FRS4002 Posts: 85Questions: 11Answers: 0
edited January 2022 in General

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?

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    You would use Orthogonal data for this. Use columns.render to replace the desired letters for the filter operation. Here is a simple example:
    http://live.datatables.net/hejimuke/1/edit

    Kevin

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0
    edited January 2022

    @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 in return data.replace, any solutions?

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    edited January 2022 Answer ✓

    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

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0
    edited January 2022

    @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...

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    If you are using columnDefs, like the test cases, make sure your columnDefs.targets is the correct column. The column numbers start counting from 0. You can also try the .replace() with the return 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

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0
    edited January 2022

    @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 the return data; at the end of the function, you mean I should do this return replace();? Maybe examples? Also maybe if you could help me privately :'( because the problem still exists ... Thanks for your helping.

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    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

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    edited January 2022 Answer ✓

    Regarding .replace() with the return data; at the end of the function, you mean I should do this return replace();?

    I meant to use the same return statement as in the if statement, for example:

    return data.replace(/احمد/gi, 'أحمد');
    

    if you could help me privately

    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

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0
    edited January 2022

    @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?

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    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 the columnDefs.targets docs for more details. Here is the updated example:
    http://live.datatables.net/labifadu/2/edit

    Kevin

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0

    @kthorngren Thanks! It worked! Thank you so much for your support! Also thanks for @colin for the support!

Sign In or Register to comment.