Multi Filtering by column on serverside table
Multi Filtering by column on serverside table
regisbs
Posts: 4Questions: 3Answers: 0
hey guys i've made a datatable using serverside with ajax however I'm not able to user column filtering i just doesn't work.
this is my code
var dataTableChamado = $('#arquivos3').DataTable({
"order": [[ 3, "desc" ]],
"processing": false,
"lengthChange": true,
"lengthMenu": [[10, 25, 50, 10000000], [10, 25, 50, "Todos"]],
"dom": 'lBfrtip',
"buttons": [
{extend: 'excel', title: 'Logic - Todos Chamados'},
{extend: 'pdf', title: 'Logic - Todos Chamados'}
],
"columnDefs": [ {
"targets": 1,
"render": function ( data, type, row ) {
return '<a href="chamado.php?id='+row[0]+'">'+data+'</a>';
}
},
{ className: "my_class", "targets": [ 0 ] },
{
"targets": 0,
"render": function ( data, type, row ) {
return '<a href="chamado.php?id='+row[0]+'">'+data+'</a>';
}
},
{
"targets": 8,
"render": function ( data, type, row ) {
if(data==1){
return '<span>Aberto</span>';
}
if(data==2){
return '<span>Fechado</span>';
}
}
}],
"serverSide": true,
"ajax": {
url: "includes/tabelaChamado.php", // json datasource
type: "post", // method , by default get
},
"initComplete": function() {
var $buttons = $('.dt-buttons').hide();
$("#pdf").on("click", function() {
$('.buttons-pdf').click();
});
$("#excel").on("click", function() {
$('.buttons-excel').click();
});
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
});
on initComplete I call all the footer selects to filter and
This discussion has been closed.
Answers
With server side processing enabled the server script is responsible for sorting and searching. The server script will need to read the parameters sent to the server for the column searching. The protocol is described here:
https://datatables.net/manual/server-side
Are you using a server side script provided by Datatables?
Kevin
kthorngren
for sure i'm using php to get mysql data and the php script returns a json data.
Which Datatables PHP script are you using?
What is the JSON data returned?
When you say it isn't working what happens? Do you get errors?
Can you post a link to your page or a test case to help you debug the problem?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
If not then try collecting debug information after you search and post the generated ID for the developers to take a look.
https://datatables.net/manual/tech-notes/10#DataTables-debugger
Kevin