Ignore accent in the input type=text

Ignore accent in the input type=text

browserbrowser Posts: 2Questions: 0Answers: 0
edited February 2010 in General
Hello:

How cai i ignore the accents in the ??

Example: If i have in a column Hell

Replies

  • Christian BonatoChristian Bonato Posts: 18Questions: 0Answers: 0
    edited February 2010
    What you can do with php (but feasible with Javascript, I guess, not to mention other programming languages) :

    Make a copy of your original strings and use a str_replace or strtr function to replace all accents with what you need.

    i.e. :

    [code]
    $stringcopy = strtr($originalstring, "()!$'?: ,&+-/.ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ",
    "--------------SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
    [/code]

    Then put the strings without accents in a column, make it searchable, and make it hidden.

    Make the column that displays the original string not searchable.


    Christian
  • browserbrowser Posts: 2Questions: 0Answers: 0
    Ok, thanks you. And if the user introduce a word with accent, how can i delete de accent ? Because if the user introduce for example Hello
  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    One thing you could do, is to detach the 'keypress' event which DataTables attaches to the 'input' element, and then add your own. Your event handler would then do something like Christian's PHP function (just in Javascript) and apply that to fnFilter ( http://datatables.net/api#fnFilter ). Then the user still has what they typed in, but you are filtering on the 'roman' alphabet :-)

    Regards,
    Allan
This discussion has been closed.