Reputation: 23
I have been working on datatables jquery plugin and on exporting the datatable to excel, numbers in a particular column are displayed in the exponential notation. How can i convert the data to text for one column only?
Upvotes: 0
Views: 2435
Reputation: 23
I found my way around this. Here is what I did
var table = $('#example').DataTable({
dom: 'BLfrtip',
pageLength: 50,
buttons: [{
extend: 'excel',
exportOptions: {
columns: ':visible'
},
Text: 'Export To Excel',
filename: 'Transaction Report',
customizeData: function (data) {
for (var i = 0; i < data.body.length; i++) {
for (var j = 0; j < data.body[i].length; j++) {
if (data.header[j] == "Column Name") {
data.body[i][j] = '\u200C' + data.body[i][j];
}
}
}
}}]});
This adds double quotes to each entry in the column
Upvotes: 1
Reputation: 389
By using exportOptions property of jquery datatable plugin you can restrict columns from exporting.
$('#myTable').DataTable( {
buttons: [
{
extend: 'excelHtml5',
text: 'Save current page',
exportOptions: {
columns: 0,1,2 //it will exporting only 3 columns out of n no of columns
}
}
]
});
By using this you can avoid exporting of problematic column !!
Upvotes: 0