How to hidden columns without data?

How to hidden columns without data?

Lucaslopez12Lucaslopez12 Posts: 14Questions: 6Answers: 0
edited January 2022 in DataTables

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

  • kthorngrenkthorngren Posts: 20,251Questions: 26Answers: 4,761

    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?

    Are you referring to the last group created by RowsGroup?

    I checked the data of my api and they arrive correctly so that is not a problem

    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

Sign In or Register to comment.