Legacy serverside processing / exporting data using TableTools

Legacy serverside processing / exporting data using TableTools

dcpdcp Posts: 5Questions: 3Answers: 0

Good morning,

I am not sure if that's the best approach, but I have (quite a lot) datatables, that use serverside processing. So I have the ability to export the visible elements, however I wanted to implement an option to export all records. I am using currently dataTables 1.9.0 with the old API.

So my first implementation was to add a custom button:

TableTools.BUTTONS.download = {
  "sAction": "text",
  "sFileName": "*.csv", // XXX
  "sFieldBoundary": "",
  "sFieldSeperator": "\t",
  "sNewLine": "",
  "sToolTip": "Export to CSV",
  "sButtonClass": "DTTT_button_csv",
  "sButtonClassHover": "DTTT_button_csv_hover",
  "sButtonText": "",
  "mColumns": "all",
  "bHeader": true,
  "bFooter": true,
  "sDiv": "",
  "fnMouseover": null,
  "fnMouseout": null,
  "fnClick": function( nButton, oConfig, oFlash ) {
    var iframe = document.createElement('iframe');
    iframe.style.height = "0px";
    iframe.style.width = "0px";
    iframe.src = oConfig.sUrl;
    document.body.appendChild( iframe );
  },
  "fnSelect": null,
  "fnComplete": null,
  "fnInit": null
};

that fetches some other URL that generates the CSV file. However thinking more about it, that means that for each API endpoint, I'll have to add an extra action to generate the whole data in CSV (currently I am using restful JSON API). So I was thinking probably it's possible to iterate through all pages (something like from 0 to dataTable.fnSettings().fnRecordsDisplay()), fetch the data via ajax and use something like:

this.fnSetData( oFlash, gatheredData )

So the question is, is there any way to format the data as CSV having a JSON result back? Or is there probably a way to create a hidden table and add results using add row and later on call something like: this.fnSetText( flash, this.fnGetTableData(oConfig) ). Ideally would be, if there is some method that I can call on the returned data and to get the data formatted using the dataTable definition already.

Thanks

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I would recommend upgrading first of all. Your DataTables is way out of date, and TableTools has not been supported for quite a while now.

  • dcpdcp Posts: 5Questions: 3Answers: 0

    Thaknks @tangerine . That's definitely on the list and I am trying slowly to migrate everything. However we've been using lot of plugins and quite a lot of tables with different configs, but I moving slowly to that direction.

This discussion has been closed.