1
votes

I have used Server-side processing https://datatables.net/examples/data_sources/server_side.html

   var table = $("#job-table").DataTable({
            "ajax": {
                url: "<?php echo url('/getJobs');?>",
                type: "POST",
                data: {
                    "connection": connectionArray,
                    "company": companyArray,
                    "type": typeArray
                }
            },
            "processing": true,
            "serverSide": true,
            "columns": [
                { "data": "id" },
                { "data": "job_id" },
                { "data": "type" },
                { "data": "connection_id" },
                { "data": "company_id" },
                { "data": "message" },
                { "data": "total_completion_time" },
                { "data": "date" },
                { "data": "start_time" },
                { "data": "end_time" },
                { "data": "error_time" }
            ]
        });

I want to call the same datatable ajax call after custom button click. On this custom button I have changed the datatable ajax call parameters. Is there any way to call the same ajax call? please help me here!

1

1 Answers

3
votes

Init datatable on document ready.

$(document).ready(function(){
    var CustomData = 'Value';
    oTable = $('#All_lists').DataTable({
        iDisplayLength:25,
        processing: true,
        serverSide: true,
        ajax: {
            "url": 'your_url',
            "type": "POST",
            "data": function (d) {
                d.key1 = CustomData,
                d.key2 = "Value2" 
            }
        },  
        columns: [
            {data: '0', name: 'branchlists.status'},
            {data: '1', name: 'branchlists.code'},
            {data: '2', name: 'fromBranch.name'},
            {data: '3', name: 'toBranch.name'},
            {data: '4', name: 'branchlists.total_receiept'},
            {data: '5', name: 'branchlists.total_parcels'},
            {data: '6', name: 'branchlists.total_weight'},
            {data: '7', name: 'branchlists.total_amt'},
            {data: '8', name: 'trips.vehicle_id'},
            {data: '9', name: 'print'}
        ],
    });
})

Change value of variable

CustomData = "ChangedValue";

After changing variable you need to reload datatable by calling below function anywhere

oTable.ajax.reload();