DataTables server-side processing - filtering issue with iso-8859-1 charset

DataTables server-side processing - filtering issue with iso-8859-1 charset

mikeowenmikeowen Posts: 4Questions: 0Answers: 0
edited April 2013 in General
Hello,

i'm using datatables with server-side processing. JSON file is encoded using ISO-8859-1 and so is the html page. All works ok except filtering - it impossible to search items that contain special characters like german letters ö, ü, ä or ß because search query is encoded using utf-8 instead of ISO-8859-1. Is there a way to encode search parameter using ISO-8859-1?

Regards,
Mike

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    DataTables itself doesn't really care about the character set. If you load your Javascript, HTML page in the same character set as the database (which I presume are all 8859-1) there shouldn't be any problems. Are they all in the same character set?

    Allan
  • mikeowenmikeowen Posts: 4Questions: 0Answers: 0
    edited April 2013
    Well, database is iso-8859-1 and I set encoding of html, javascript and json to iso-8859-1 but it didn't help. Parameters of ajax request are still encoded using utf-8 instead of iso-8859-1 e.g. when I type ü in search box the ajax request looks like this: GET /json?sEcho=12&sSearch=%C3%BC and it should look like this:
    GET /json?sEcho=12&sSearch=%FC (other parameters omitted for brevity)
    To sum up: the datatable displays fine, but it's impossible to use special characters in search query when ISO-8599-1 encoding is used (everything works fine for utf-8).

    Is there a way to force datatables/jquery to encode url parameters using iso-8859-1?
  • mikeowenmikeowen Posts: 4Questions: 0Answers: 0
    edited April 2013
    OK, I've just learned that jquery always encodes parameters of ajax requests (GET or POST) using utf-8 (this is actually standard encoding for XMLHttpRequest). Since filtering is implemented as a ajax request, it's only possible to use ISO-8859-1 (latin1) when data is decoded on server side (from utf-8 to latin1). Unfortunately this is not possible in my case :(
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    That's really annoying - I'm surprised XHR doesn't just use the page's character set, but not much I can do about it in DataTables I'm afraid. Perhaps you could use something like `iconv` to convert from one character set to the other?

    Allan
  • mikeowenmikeowen Posts: 4Questions: 0Answers: 0
    edited April 2013
    Yes, I would use iconv to convert from utf8 to latin1 but unfortunately I can't change scripting on this site. Your software is great but I'd love to see a PHP version of datatables that wouldn't require javascript/ajax someday :-)
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    DataTables is a Javascript library, so there is not likely to be a Javascript free version any day :-).

    Allan
This discussion has been closed.