1

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!

0

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

8 Comments

how can we use datatable ajax response data outside? I want to use one response parameter and set it to span!
I guess you can use datatable init callback function. drawCallback
@Progi1990, Did you find solution with callback function?
not yet! :( thought I have tried with success method inside datatable but it seems to not working there ... I can consoled the value or I can get it in success method but datatable shows processing using drawCallback function I have get only table data not the parameters which I have sent in response!
You get what you wanted, AJAX response of datatable. What else you need?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.