Updating Exported Data

Updating Exported Data

BenKatzBenKatz Posts: 4Questions: 0Answers: 0
edited December 2011 in TableTools
I'm dynamically updating (via jQuery .load) content in my table. When I go to export data (PDF, .csv or text), it exports the data as of when TableTools was initialized.

I don't want to re-initialize TableTools every time data changes. Is there a way to have the data update on export? Any other suggestions?

Thanks!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you are updating the content in the table, you need to be using the DataTables API methods, specifically fnUpdate (possibly fnDeleteRow and fnAddData as well). Otherwise DataTables won't know that you've changed the data, and thus, sorting, filtering and TableTools won't work.

    Allan
  • BenKatzBenKatz Posts: 4Questions: 0Answers: 0
    Thank you. Worked perfectly. I didn't want to rewrite existing code to pipe everything through fnUpdate, so I instead put together a function for calling it after an update. Posted below in case it will help someone else.

    [code]
    function dataTablesRefreshCell($cell){
    var col = $cell.parent().children().index($cell);
    var row = $cell.parent().parent().children().index($cell.parent());
    $cell.closest("table").dataTable().fnUpdate($cell.html(),row,col);
    };
    [/code]
  • BenKatzBenKatz Posts: 4Questions: 0Answers: 0
    edited December 2011
    Ignore my previous code as it is not working properly with pagination. Here's revised code:

    [code]
    function dataTablesRefreshCell($cell){
    oTable=$cell.closest("table").dataTable()
    var pos = oTable.fnGetPosition($cell[0]);
    oTable.fnUpdate($cell.html(),pos[0],pos[1],false,false);
    };
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Nice function - thanks for sharing that with us!

    Allan
This discussion has been closed.