Is there any way to export an Excel file with all data from a datatable with server side query?
Is there any way to export an Excel file with all data from a datatable with server side query?
AliSharafi
Posts: 1Questions: 1Answers: 0
Is there any way to export an Excel file with all data from a datatable with server side query?
Here is my CreateTable function written in typescript. Any suggestion is welcome.
createTable() {
var $this = this;
// Setup - add a text input to each footer cell
$('#trackings-table tfoot th:not(:first-child)').each(function () {
var title = $(this).text();
$(this).html('<input type="text" />');
});
var table = $('#trackings-table').DataTable({
"dom": 'lBrtip',
"processing": true,
"serverSide": true,
"ajax": {
"url": this.url,
"type": "POST",
"contentType": 'application/json',
"data": function (request) {
return JSON.stringify(request);
},
"dataSrc": function (response) {
return response.data;
},
"beforeSend": function (xhr) {
xhr.setRequestHeader("Authorization", $this.user.getTokenBearer());
}
},
"columnDefs": [
{
"targets": 0,
"name": "Icon",
"searchable": false,
"orderable": false
},
{
"targets": 1,
"name": "Date"
},
{
"targets": 2,
"name": "Entrance"
},
{
"targets": 3,
"name": "Action"
},
{
"targets": 4,
"name": "Tag"
},
{
"targets": 5,
"name": "Person"
},
{
"targets": 6,
"name": "Readergroup"
},
{
"targets": 7,
"name": "Reader"
},
{
"targets": 8,
"name": "FacilityTo",
"visible": false
},
{
"targets": 9,
"name": "Message"
},
{
"targets": 10,
"name": "ID",
"visible": false
}
],
"order": [[1, "desc"]],
"buttons": [
<any>{
extend: 'colvis', titleAttr: this.translator.tr('ID_TOGGLE_COLUMNS'), // 'Toggle columns',
text: this.translator.tr('ID_COLUMNS'),
columns: ':gt(0)'
},
{
extend: 'excel', titleAttr: this.translator.tr('ID_EXPORT_TO_EXCEL'), // 'Export to excel',
exportOptions: {
columns: <any>[':visible:not(.noExport)']
},
},
{
extend: 'csv', titleAttr: this.translator.tr('ID_EXPORT_TO_CSV'), // 'Export to csv',
exportOptions: {
columns: <any>[':visible:not(.noExport)']
}
}
],
"pageLength": 15,
"deferRender": true, // Load only the nodes visible on the page (Speeds up to 50,000 records)
"lengthChange": true,
"lengthMenu": [[10, 15, 25, 50, -1], [10, 15, 25, 50, this.translator.tr('ID_ALL')]],
"stateSave": true,
"searchDelay": 1000,
"language": {
"url": "/locales/" + this.globalDef.language + "/datatable.json"
},
// Use initcomplete cause language file loads async causing problems
"initComplete": function (settings, json) {
$this.isInitialized = true;
// Dynamic table visibility
$('a.toggle-vis').on('click', function (e) {
e.preventDefault();
var column = table.column($(this).attr('data-column'));
column.visible(!column.visible());
});
// Restore state
var state = table.state.loaded();
if (state) {
table.columns().every(function () {
var that = this;
if (that.search()) {
$('input', that.footer()).val(that.search());
}
});
table.draw();
}
// Apply the search using enter
//$('input', this.footer()).keypress(function (e) {
// if (e.which == 13) {
// $this.applySearch();
// return false;
// }
//});
}
});
this.table = table;
}
This discussion has been closed.
Answers
Hi @AliSharafi ,
There's a few threads on this, including the FAQ. The short answer is no, I'm afraid.
Cheers,
Colin