DataTables - Case Sensitive Doesn't Work for Some Characters

DataTables - Case Sensitive Doesn't Work for Some Characters

ocelikdemirocelikdemir Posts: 2Questions: 1Answers: 0

jQuery DataTables doesn't work for some local characters like uppercase "İ" and lowercase "ı". I tried case sensitive setting for "search" function but nothing changed.

I have created the following fiddle. Could you please check what I am doing wrong?
jsFiddle - Case Sensitive Issue

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Rather curoious this. Just plain Javascript in the console:

    'ÇELİKDEMİR'.toLowerCase()
    > "çeli̇kdemi̇r"
    
    'Çelikdemir'.toLowerCase()
    > "çelikdemir"
    

    Looks good. However:

    'Çelikdemir'.toLowerCase() === 'ÇELİKDEMİR'.toLowerCase()
    > false
    

    If I print out the character code from each string we can see why that is:

    ÇELİKDEMİR = 231 101 108 105 775 107 100 101 109 105 775 114
    Çelikdemir = 231 101 108 105 107 100 101 109 105 114
    

    Even using toLocaleLowerCase makes no difference.

    I think the closest we can get to supporting this is with this plug-in. Here is an updated example with it.

    The downside is that you can't filter on a string which mixes non-ASCII characters and not. You either need to search with ASCII characters, which will match, or with the exact non-ASCII characters, which would also match. However Çelikdemir would not match since it is a mix of the two.

    Allan

  • ocelikdemirocelikdemir Posts: 2Questions: 1Answers: 0
    edited June 2023

    Dear Allan,
    I found out another way. I know, it's not good way but it works. I have converted input field value as well as table values to uppercase on the fly. I modified the DataTables search function as below:

      "sSearch": val.toLocaleUpperCase('tr'),
      "bRegex": previousSearch.bRegex,
    

    Github - Search Function

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Nice one - thanks for sharing that. This might be a really useful thing to include in the core, in a locale specific way, so I'll look into it further.

    Allan

Sign In or Register to comment.