tablesorter
tablesorter copied to clipboard
Unable to download table as excel.
Here is my code but it does not seem to download anything. Also advise how to download as an excel with the column header and filtered subset on the table.
I followed the https://github.com/Mottie/tablesorter/issues/963
Is there a specific version I need to be using?
$(function () {
var $table = $('table');
$('#exportGrid').click(function () {
$table.trigger('outputTable');
});
$table.tablesorter({
theme: 'blue',
widgets: ['zebra', 'output'],
widgetOptions: {
output_delivery: 'd',
output_separator: ';'
}
});
})
Hi @rdasgupta7141!
No specific version. Please follow the examples in the issue that you shared. You'll need to include the output_callback
function along with one of the excel JS library to export an excel directly. Or just download the table as a CSV and import it into excel.
Thanks @Mottie for your response. I don't see anything happening when I click on the download button. I followed along that example.
$(function () {
var $table = $('table');
$('#exportGrid').click(function () {
$table.trigger('outputTable');
});
$('table').tablesorter({
theme: 'blue',
widgets: ['zebra', 'filter', 'output'],
widgetOptions: {
output_separator: 'array',
output_saveFileName: 'test.xlsx',
output_callback: function (config, data) {
// data is set to be an array of arrays
var wbout,
wo = config.widgetOptions,
ws_name = "SheetJS",
wb = new Workbook(),
ws = sheet_from_array_of_arrays(data);
/* add worksheet to workbook */
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;
wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'binary' });
saveAs(new Blob([s2ab(wbout)], { type: "application/octet-stream" }), wo.output_saveFileName);
// stop further output widget processing
return false;
}
}
});
})
<button id="exportGrid" type="button" class="btn btn-sm btn-success" >
<i class="glyphicon glyphicon-save"></i>
Excel File
</button>
<div class="table-responsive">
<table class="tablesorter table table-bordered table-striped table-hover table-condensed">
<thead>
</thead>
<tbody>
</tbody>
</table>
<div class="table-responsive">
<table class="tablesorter table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
<th>
Did you include the js-xlsx library? https://github.com/SheetJS/sheetjs#installation
I did download xlsx.core.min.js and added to the layout.cshtml.
How may I even have it download as a csv? I don't see anything happening after the code executes the following line. $table.trigger('outputTable');
I might not be including all the .js files right for tablesorter. So I added the following in my layout.cshtml
wwwroot/lib/jquery.tablesorter/js/jquery.tablesorter.js, wwwroot/lib/jquery.tablesorter/js/extras/jquery.tablesorter.pager.min.js lib/jquery.tablesorter/js/widgets/widget-output.min.js I am pretty sure I am missing something. Please let me know what I may be doing wrong.