custom filter in datatable

0

Good morning!

There is a certain time, that I have to make an advanced filter on the server side. I thought of two possibilities in sending the parameters in fnserverdata, which did not work very well, so I decided to send the parameter via Ajax

Here is an example of my ajax

$("#btnFiltrar").click(function(){
    if(document.getElementById("inputNao").checked){
        var inputNao = $("input[id=inputNao]").val();
        $.ajax({
            type:'GET',
            url:'json/ssp.class-license.php',
            data:{
                specialClientesYes:inputNao
            }
        })
    }
});
$("#btnFiltrar").click(function(){
    if($("#cmbVersao").find(":selected").text() != "Selecione"){
        var versao = $("#cmbVersao").find(":selected").text();
        $.ajax({
            type:'GET',
            url:'json/dados-license.php?version='+versao
        })
    }
});
$("#btnFiltrar").click(function(){
    if($("#txtUsuariosDe").val() != ""){
        var usuariosDe = $("#txtUsuariosDe").val();
        $.ajax({
            type:'GET',
            url:'json/ssp.class-license.php',
            data:{
                earlyUsers:usuariosDe
            }
        })
    }
});

My biggest problem is to get this value where the server side is and filter it How to handle this value?

    
asked by anonymous 05.08.2016 / 15:11

2 answers

0

Looking at the examples on the datatables site, I imagine you'd better use their api, instead of customizing ajax for each query. See the examples below:

function filterGlobal () {
    $('#example').DataTable().search(
        $('#global_filter').val(),
        $('#global_regex').prop('checked'),
        $('#global_smart').prop('checked')
    ).draw();
}



function filterColumn ( i ) {
    $('#example').DataTable().column( i ).search(
        $('#col'+i+'_filter').val(),
        $('#col'+i+'_regex').prop('checked'),
        $('#col'+i+'_smart').prop('checked')
    ).draw();
}
    
05.09.2016 / 15:51
0

As you are passing the parameters by GET , so you capture in the server-side : $_GET['nome_do_parametro'];

    
20.01.2018 / 22:20