Update Table after change select values Datatable

Update Table after change select values Datatable

Danillo Leão LopesDanillo Leão Lopes Posts: 3Questions: 2Answers: 0

I'm try to update the table after change the select value, i got error: DataTables warning: table id=regrasimpostos - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

// Document.Ready()
**let imposto = $("#imposto").dropdown("get value");

tabela_imposto = $("#regrasimpostos").DataTable({
    "language": {
        "url": host+"/js/Portuguese-Brasil.json"
    },
    "serverSide": true,
    "ajax": `/pesquisa/regraimposto/${imposto}`,
    "columns": [
        {"data" : "impostoNome"},
        {"data" : "modelo"},
        {"data" : "pessoa"},
        {"data" : "contribuinte"},
        {"data" : "estado"},
        {"data" : "cfop"},
        {
            "data" : null,
            defaultContent: `<a href="#" title="Editar" data-id="impostoID" onclick="editarRegra('variavel')"><i class="edit icon"></i></a>`
        }
    ]
})**

// AFTER CHANGE SELECT CALL
function pesquisaRegrasImpostos(imposto){
if (imposto != "") {
$.ajax({
url: /pesquisa/regraimposto/${imposto},
success: function(data){
tabela_imposto.ajax.url(data).load();
},
error: function(error){
alert(JSON.stringify(error));
}
});
}
}

// LARAVEL DATATABLES
**public function pesquisaRegraImpostoProduto(Request $request, $imposto)
{

    return DataTables::of(ItensController::getRegrasImpostos($request, $imposto))->make(true);

}**

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929
    Answer ✓

    Did you follow the steps in the URL linked to in the error message?
    http://datatables.net/tn/1

    My guess is the issue is the URL you are trying to use in the success function:

    success: function(data){
    tabela_imposto.ajax.url(data).load();
    },
    

    What is the value of data?

    Kevin

  • Danillo Leão LopesDanillo Leão Lopes Posts: 3Questions: 2Answers: 0

    oh man, really!

    only it:

    function pesquisaRegrasImpostos(imposto){
    let url = /pesquisa/regraimposto/${imposto};
    tabela_imposto.ajax.url(url).load();
    }

This discussion has been closed.