custom datatable filter

Asked

Viewed 1,030 times

0

Good morning!

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

Follow an example from 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 difficulty is to take this value where does the server side and make it filter How to treat this value?

2 answers

0

Looking at the examples on the datatables website, I imagine it’s best that you use their api, rather than you 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();
}

0

Like you’re passing the parameters by GET, you catch like this on server-side: $_GET['nome_do_parametro'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.