How to hidden columns without data?
How to hidden columns without data?
Hello. I have a table with columns that do not show the data or do not bring anything. How can I hide the columns that are empty?
My table:
`const tableRanking = $("#sellersQuantityTable").DataTable({
responsive: true, "lengthChange": false, "autoWidth": false, "searching": true, fixedHeader: true, "scrollX": true,
buttons: [
{
extend: "excel",
title: '',
filename: 'Venta por Financiera',
exportOptions: { orthogonal: 'export' },
}],
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api();
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
rendered = api
.cells( null, 1, { page: 'total'} )
.render('display')
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
console.log(rendered)
pageTotal = api
.column( 1, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column(1).footer() ).html(
'TOTAL: '+pageTotal + '(' + rendered +')'
);
},
language: {
"url": "//cdn.datatables.net/plug-ins/1.10.24/i18n/Spanish.json"
},
columns: [
{ "data": "MarcaTotal" },
{
"data": "MontoMarca", render: function (data, type, row) {
return type === 'export' ?
data.replaceAll(/[$ |.]/g, '').replace(',', '.') :
data;
},
},
],
order: [[1, "desc"]],
rowsGroup: [0]
}); `
I checked the data of my api and they arrive correctly so that is not a problem
Answers
Are you referring to the last group created by RowsGroup?
RowsGroup is creating groups based on the data in column 0, ie,
rowsGroup: [0]
. Assuming the plugin is working correctly then you have empty data in that column. Without seeing the problem its hard to say what is happening. Please post a link to your page or a test case showing the problem.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin