key problems with accent (spanish)

key problems with accent (spanish)

nestoronaldnestoronald Posts: 5Questions: 0Answers: 0
edited December 2013 in General
Hello, I have problems with accented words filter. Example: I have a table with data:
1. Juan Perez
2. Jose Pérez
3. Pedro Pèrez.
Write "Perez" and I only filter: 1. Juan Perez. I want to filter all the "Perez" with or without accent.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    This is definitely a bit of a problem at the moment. The problem basically is that DataTables uses straight string matching, and `é !== e` etc - hence why it doesn't match. What I think would probably be needed is a filtering formatter, which is certainly possible (at least in 1.10, I'm not sure that it is in 1.9...) but then, you need to consider the case when your user does search for `é` rather than `e` . It would be relatively simple to replace all accented characters with their non-accented counterparts, but it would mean that filtering with accented characters wouldn't work...

    Here is an example of how you could modify the built-in search string formatter in 1.10 to remove the accents and filter only on non-accented characters.

    [code]
    $.fn.DataTable.ext.type.search.string = function ( data ) {
    return ! data ?
    '' :
    typeof data === 'string' ?
    data
    .replace( /\n/g, " " )
    .replace( /é/g, 'e' )
    .replace( /ê/g, 'e' )
    .replace( /è/g, 'e' ) :
    data;
    }
    [/code]

    1.10 is pre-beta, but it is available as the nightly on http://datatables.net/download .

    Let me know how you get on with it!

    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [code]
    $.fn.DataTable.ext.type.search.string = function ( data ) {
    return ! data ?
    '' :
    typeof data === 'string' ?
    data
    .replace( /\n/g, " " )
    .replace( /[éêè]/g, 'e' ) :
    data;
    }
    [/code]

    would be more efficient thinking about it. Obviously the other accented characters would need to be added as well.

    Allan
  • nestoronaldnestoronald Posts: 5Questions: 0Answers: 0
    Hi, i downloaded the version 1.10 of datatable, insert the code in my project and still the problem.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Can you please link to the page showing the problem. I've just tried it and it worked okay.

    Allan
  • nestoronaldnestoronald Posts: 5Questions: 0Answers: 0
    Here the link:
    http://immense-journey-5655.herokuapp.com/
    Help please.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Put the DataTables initialisation _after_ you modify how the search works :-)

    Allan
  • nestoronaldnestoronald Posts: 5Questions: 0Answers: 0
    Thanks, it works
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Excellent! I'll look at creating a proper published plug-in for this at some point then which deals with all accented characters.

    Allan
This discussion has been closed.