How to catch changes to configuration like sort, page etc?

How to catch changes to configuration like sort, page etc?

rushrush Posts: 4Questions: 0Answers: 0
edited January 2010 in General
Hi I would like to catch changes that user does to the data tables like changing the sort, page, etc, so that i can communicate it through ajax to the server to e stored there.

Any hint how to accomplish that?

Many thanks!

Replies

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin
    Hi rush,

    There isn't currently a specific way for capturing an event such as sorting or filtering (my ideas for DataTables 2.x will introduce that then, whenever it happens... :-) ) but it is possible to looks for these changes yourself, and write a function which will detect them and do whatever you require.

    The way to do this is to use fnDrawCallback and fnSettings. In the draw callback function you can check to see if any of the configuration has changed (through checking the settings object obtained from fnSettings). aaSorting for example is the array containing the sorting information.

    Another option might be to use the save settings functions (or indeed just turn it on and read the cookie in fnDrawCallback - set the cookie duration to 1-3 second(s) if you don't want it to be retained) and send that information (it's a json object) to the server.

    Hope that helps,
    Allan
  • rushrush Posts: 4Questions: 0Answers: 0
    When is save settings function called? each time something changes in settings? If so maybe I could substitute it with my function that goes to the server. What is the name of the standard save settings function , and is there a place I could store reference to my function instead of standard one?

    If not I would go fnDrawCallback way, I guess that it will always be called if there is change in settings.

    Many thanks.
  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin
    Hi rush,

    _fnSaveState is the function you are looking for. It's called whenever the save is changed (which is more or less every draw). Sounds like a good idea to modify / replace this function with whatever you need. :-)

    Regards,
    Allan
This discussion has been closed.