Trigger the change table content.

Trigger the change table content.

antonio77antonio77 Posts: 17Questions: 0Answers: 0
edited April 2011 in General
Hi all,
what is the best way to trigger the table redraw after action like filtering, sorting or showing different rows?
I'm using the jquery.dataTables version 1.7.6,
and, possibly, I don't want to modify the original plugin.
Thanks,
Antonio

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    Not sure if this answers your question or not, but redraw should be automatic for most of those actions. For example, filtering: as you type characters into the search field, DataTables will filter based on the string created by each new character and automatically update the table. If you're using server-side processing, each new character triggers an Ajax request and the server side is expected to do the sorting before returning a pre-sorted data set; at which time the table is redrawn.

    If I'm misunderstanding and you need to explicitly call a redraw function anyhow, you can call fnDraw(). So once your table is initialized, $('#myTable').dataTable().fnDraw() will get data according to the data source in the initialization and then redraw the table.

    My application does polling, so regardless of sorting, filtering, etc., every 3 seconds I call fnDraw() on the table, which fetches the new data set and redraws the table.
  • antonio77antonio77 Posts: 17Questions: 0Answers: 0
    Thanks @GregP for your replay,
    and sorry if my question was not clear.
    Indeed, I need to call a external javascript function after the content of table changes because of filtering or sorting action for example.
    I know how to make it for filtering for example, but I'm looking for a common method to make it after the table is redraw because of change of table content.
    The data are all in client side part.
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Oh weird, could've sworn I replied to this. Must've forgot to submit or something...!

    You can hook into one of the callbacks: http://datatables.net/usage/callbacks

    The obvious choice seems to be fnDrawCallback. Filter triggers an automatic draw, and in turn fnDrawCallback can call whatever external function you need.
  • antonio77antonio77 Posts: 17Questions: 0Answers: 0
    Thanks @GregP, fnDrawCallback fits the purpose perfectly.
  • markjomarkjo Posts: 66Questions: 0Answers: 0
    @GregP thanks. that info helped me too :)
This discussion has been closed.