How to get the filtered data on every change/update?

How to get the filtered data on every change/update?

nerd1337nerd1337 Posts: 2Questions: 0Answers: 0
edited November 2011 in General
Hi there!

I've a table and would like to send the filtered data to another script (php) that outputs a graph above the table.

I found the method fnGetDisplayNodes() but don't know how to use it the way I need. Everytime the filter gets changed I would like to update the graph with new data, is there any event like oTable.onUpdate(/* send displayed nodes to the graph-script */)?

Thanks in advance!
nerd1337

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited November 2011
    fnDrawCallback: http://www.datatables.net/ref#fnDrawCallback

    if you're using server-side sourced data, you could send the JSON contents to some other routine to feed your graph, in the fnServerData routine. else you'll probably want to use fnGetNodes and fnGetData to fetch data from the filtered set and pass to your graph.
  • nerd1337nerd1337 Posts: 2Questions: 0Answers: 0
    @fbas: Thanks a lot, fnDrawCallback what exactly what I was searching for.

    I'm using fnGetData and get the whole data, not just the filtered ones. I tried fnGetNodes but got no suitable solution, as well. Does anybody know how to get just the filtered data?

    Thanks again!
  • maatermaater Posts: 2Questions: 0Answers: 0
    @nerd1337,

    I want the same functionality.

    Did you even find a solution to this?

    Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    DataTables 1.9 (currently beta) has a possible solution for you - the new API method '$' has the option of selecting all rows, or only filtered rows: http://datatables.net/docs/DataTables/1.9.beta.1/#$_details

    [code]
    table.$('tr', {"filter": "applied"} );
    [/code]

    will get you a jQuery object with the TR elements that remain after the filter. From there you can loop over them using fnGetData.

    There is also this API method that would do it: http://datatables.net/plug-ins/api#fnGetFilteredData

    Allan
This discussion has been closed.