fnrowcallback search

fnrowcallback search

dan1dyoungdan1dyoung Posts: 2Questions: 0Answers: 0
edited February 2014 in DataTables 1.9
Hi,

We use the fnrowcallback to translate the tables contents on the fly but the search (Filter) only works with the original untranslated data loaded from the JSON request. So if we send the JSON in English and then translate to Finnish we have to still search in english.

Can this be achieved, changing the search to look at the modified data??

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    This is possible, but not with fnRowCallback . You don't really want to use fnRowCallback for very much to be honest (I should put a health warning in its documentation!). The problem with fnRowCallback is that it is called for the row, every time it is displayed. Sometimes useful, but not very often...

    The end result would be that if you doing something like translating data, you might be translating the same string multiple times, which would just put unnecessary load on the processor.

    What I would suggest you do is transform the JSON as it comes in. In DataTables 1.10 you can use `ajax.dataSrc` to do that ( http://next.datatables.net/reference/option/ajax.dataSrc ). In 1.9- you need to use fnServerData to write your own Ajax call with the transform in it.

    This way the data is translated only once, and the translated data will be used for search, sort etc.

    Does that make sense? Sounds like an interesting application! How are you doing the translation, is it a simple token lookup?

    Allan
  • dan1dyoungdan1dyoung Posts: 2Questions: 0Answers: 0
    Hi Allan,

    Using mRender instead of fnRowCallback works, but is there a downside to this and so a reason to use your way as above??

    It is not me coding this but I will let you know the setup.

    Thanks

    Dan
This discussion has been closed.