dan3460
227
6
Laravel

Datatable draw not updating post variable

Posted 2 months ago by dan3460

I'm using Yajra Datatables, I have a select that returns 0,1 or 2 and depending on that the datatable is populated. My problem is when changing the selection the "type" variable still the one on the first selection. In other words the type still 0 regardless of what was selected. The alert that i have in the change, shows the selection chaging, but the draw has the old data:

    $(document).ready(function(){
    var batchesTable = $('#batches').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: '/getBatches',
            type: 'post',
            data: {
                _token: "{{csrf_token()}}",
                type: $("#type").val()
            }
        },
        columns:[
            {data: 'id', name: 'id'},
            {data: 'name', name: 'name'},
            {data: 'debit', name: 'debit'},
            {data: 'credit', name: 'credit'},
            {data: 'updated', name: 'updated'},
            {data: 'posting', name: 'posting'},
            {data: 'action', name: 'action'}
        ]
    });

    $("#type").change(function(){
        alert($("#type").val());
        batchesTable.draw();
    });
})

Please sign in or create an account to participate in this conversation.