I want to show and hide the columns of a table, but I get the following error
ReferenceError: table is not defined
And my code is as follows:
oTable = $('#pedidos-table').DataTable({
"processing": true,
"oLanguage": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "No se encontraron resultados",
"sEmptyTable": "Ningún dato disponible en esta tabla",
"sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
"sInfoPostFix": "",
"sSearch": "",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "Cargando...",
"oPaginate": {
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
}
}
});
var thead = [];
var count = 0;
$("#pedidos-table thead tr th").each(function() {
thead.push($(this).text());
});
thead.forEach(function(dato) {
$(".breadcrumb").append("<li class='breadcrumb-item' data-column='"+count+"'><a>"+dato+"</a></li>");
count ++;
});
$(".breadcrumb-item").click(function(e){
e.preventDefault();
// Get the column API object
var column = table.api().column( $(this).attr('data-column') );
// Toggle the visibility
column.visible( ! column.visible() );
});
});
It would be as follows