TableExport icon indicating copy to clipboard operation
TableExport copied to clipboard

reinitiate table export on custom button

Open haruhinoshana opened this issue 8 years ago • 1 comments

hi everyone,

      Im having issue re initiate the plugin when i filtered the table the code is below.

code when im calling the plugin //withdrawal var instance_withdrawal=$("#withdrawal_tbl").tableExport({ headers: true, // (Boolean), display table headers (th or td elements) in the , (default: true) footers: true, // (Boolean), display table footers (th or td elements) in the

, (default: false) formats: ['xls'], // (String[]), filetype(s) for the export, (default: ['xls', 'csv', 'txt']) filename: 'Significant Withdrawals Report', // (id, String), filename for the downloaded file, (default: 'id') bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) exportButtons: false, // (Boolean), automatically generate the built-in export buttons for each of the specified formats (default: true) position: 'bottom', // (top, bottom), position of the caption element relative to table, (default: 'bottom') ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null) ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null) trimWhitespace: true // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false)
});

var exportData_withdrawal = instance_withdrawal.getExportData()['withdrawal_tbl']['xls']; //console.log(exportData);

$("#withdrawal_btn").click(function(){
instance_withdrawal.export2file(exportData_withdrawal.data, exportData_withdrawal.mimeType, exportData_withdrawal.filename, exportData_withdrawal.fileExtension); });

but i need to re initiate the plugin because i filtered it

how can i reset the values on the custom button use..

my code on ajax to reinitate the table.

$("#significantsw-btn").click(function(){ //alert("x"); //check if blanks... if($("#sw_from").val()=='' || $("#sw_to").val()==''){ bootbox.alert("Please fill up all fields."); return false; }

$.ajax({
  url: 'url',
  type: 'POST',
  dataType: 'html',
  data: {

... ... }, complete: function(xhr, textStatus) { //called when complete }, success: function(data, textStatus, xhr) { withdrawal.fnDestroy();

    $("#sw_tbody").html(data);
    instance_withdrawal.reset();
    withdrawal = $("#withdrawal_tbl").dataTable();

  },
  error: function(xhr, textStatus, errorThrown) {
    //called when there is an error
  }
});

});

please help im newbie to use this plugin....

haruhinoshana avatar Aug 31 '17 21:08 haruhinoshana

I am having the same issue. It seems that {TABLE}.getExportData() will only return the info for the first time the table was instantiated. Calls to {TABLE}.getExportData() after .update() or .reset() seems to ignore the fact that the table has been changed.

Please see my CodePen below. https://codepen.io/StuffieStephie/pen/rrLeLp

In the short term, just create a new instance of the table.

StuffieStephie avatar Jul 17 '18 18:07 StuffieStephie