I am using Datatable and correctly fetching data as expected but in a situation where I want to export data on excel button I want some data in A1 and B1 cell then my regular table content should export. I tried customize
option of datatable but it didn’t work like I needed.
Here is my code:-
$("#boms-table").DataTable({
"responsive": true,
"lengthChange": false,
"autoWidth": true,
"paging": false,
"searching": true,
"info": false,
"buttons": [{
extend: 'excel',
exportOptions: {
columns: ':visible:not(.exclude)'
},
title: "",
customize: function(xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr('s', '50');
var a1 = $('row c[r^="A1"]', sheet);
a1.html('<is><t>' + materialPartcode + '</t></is>');
var b1 = $('row c[r^="B1"]', sheet);
b1.html('<is><t>' + materialDesc + " - BOM" + '</t></is>');
$('row').eq(1).addClass('ignore');
$('row c', sheet).each(function() {
if ($(this).index() > 1) {
var selectedRow = $(this).parent();
var columnIndex = $(this).index();
selectedRow.find('c[r^="A"]').eq(columnIndex).addClass('ignore');
selectedRow.find('c[r^="B"]').eq(columnIndex).addClass('ignore');
}
});
$('.ignore', sheet).attr('s', '2');
},
},
{
extend: 'pdf',
exportOptions: {
columns: ':visible:not(.exclude)'
},
title: materialPartcode + " - " + materialDesc + " - BOM",
},
{
extend: 'print',
exportOptions: {
columns: ':visible:not(.exclude)'
},
title: materialPartcode + " - " + materialDesc + " - BOM",
},
'colvis'
],
}).buttons().container().appendTo('#boms-table_wrapper .col-md-6:eq(0)');
All I want is “materialPartcode” in A1 cell then “materialDesc” in B1 cell then all the table contents. Kindly help!!!