Refresh Data from a select drop down.

Refresh Data from a select drop down.

Dan3460Dan3460 Posts: 3Questions: 2Answers: 0
edited June 2019 in Free community support

Im working with Laravel and run into the following problem (also using Yajra Datatables) . I have a table that shows data depending on a selection from a drop down. When the page loads the datatable is filled with the correct data, but when selecting another option the requested data is the same as what was requested the first time.I put that alert on the change function to see if the value changed and it does.
Here is the code:

        $(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();
        });

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @Dan3460 ,

    It's probably because it's ajax.data isn't a function - so the value it's sending will always be the value when the table was first initialised. Try changing it to be a function like the last three examples on that page,

    Cheers,

    Colin

This discussion has been closed.