My filter by column doesn't work
My filter by column doesn't work
xiul
Posts: 7Questions: 3Answers: 0
I really appreciate if anyone could help me with my datatable because it is not working and I don't know why, Post my code below.
detalle = $("#detalle-table").DataTable({
"ajax": {
url: "ajax/cargar_reportedetalle",
type: "POST",
data: {
idsocio: idsocio,
idusuario: idusuario
},
dataSrc: "",
complete: function(data){
if(Object.keys(data.responseJSON).length == 3){
var mensaje = data.responseJSON.mensaje;
if(mensaje != null){
alert(mensaje);
}
}
}
},
columns: [
{ data: "contador" },
{ data: "idtipounidad" },
{ data: "idunidad" },
{ data: "idcarroceria" },
{ data: "noeconomico" },
{ data: "marca" },
{ data: "modelo" },
{ data: "placas" },
{ data: "tipounidad" },
{ data: "socio" },
{ data: "km" },
{ data: "estatus" },
{ data: "serie"}
],
columnDefs: [
{ className: "cssbold text-center", targets: [0] },
{ className: "text-center", targets: "_all" },
{ "targets": [ 1 ], "visible": false },
{ "targets": [ 2 ], "visible": false },
{ "targets": [ 3 ], "visible": false }
],
initComplete: function () {
var r = $('#detalle-table tfoot tr');
r.find('th').each(function(){
$(this).css('padding', 8);
});
$('#detalle-table thead').append(r);
detalle.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
},
autoWidth: false,
searching: false,
info: false,
pageLength: 10,
pagingType: "full_numbers",
fixedHeader: {
header: true,
footer: true
}
});
});
var contador = 0;
$('#detalle-table tfoot th').each( function () {
var title = $(this).text();
if(contador > 0){
$(this).html('<input type="text" id="filtro' + contador + '" class="form-control form-control-sm"'
+ 'style="width: 100%;" placeholder="Buscar ' + title + '" />');
}
contador++;
} );
This discussion has been closed.
Answers
I don't see anything that stands out as an issue. Can you create a simple test case replicating the issue so we can help debug?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin