2
I have several tables, one on each page of my application and all will have the same function of filtering a column, but the columns have different names and different orders.
How to write this code without getting repetitive?
$(document).ready(function(){
// Filtro da tabela em fila
var em_fila = $('#em_fila').dataTable({
"sDom": "t",
"paging": false,
"ordering": false,
"info": false
}
);
$('.select-category').change( function () {
em_fila.fnFilter($('.select-category').val(), 0);
});
// Filtro da tabela digitação
var em_digitacao = $('#em_digitacao').dataTable({
"sDom": "t",
"paging": false,
"ordering": false,
"info": false
}
);
$('.select-category').change( function () {
em_digitacao.fnFilter($('.select-category').val(), 0);
});
// Filtro da tabela com erros
var com_erros = $('#com_erros').dataTable({
"sDom": "t",
"paging": false,
"ordering": false,
"info": false
}
);
$('.select-category').change( function () {
com_erros.fnFilter($('.select-category').val(), 0);
});
// Filtro da tabela com em_recebimentos
var em_recebimentos = $('#em_recebimentos').dataTable({
"sDom": "t",
"paging": false,
"ordering": false,
"info": false
}
);
$('.select-category').change( function () {
em_recebimentos.fnFilter($('.select-category').val(), 0);
});
});
Why have you complicated the selector so much? A simple
table.datatable-defaults
would give the same result.– Oeslei