0

I am using jQuery datatable plugin for display data but getting this error: aoData.push is not a function when I am passing my custom variable to datatable.

Any idea about this error?

Here is my script code:

$(document).ready(function() {
    table = $('#table').DataTable({

        "processing": true, // Feature control the processing indicator.
        "serverSide": true, // Feature control DataTables' server-side processing mode.

        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "<?php echo site_url('admin/invite_instagrammers/GetInstagrammersData')?>",
            "type": "POST"
        },

        // "fnServerParams": function (aoData) {
        //     aoData.push({name: "pid", value: '15'});
        // },

        "oLanguage": {
            "sProcessing": "Loading records..."
        },

        // Set column definition initialisation properties.
        "columnDefs": [{
            "targets": [-1], // Last column
            "orderable": false, // Set not orderable
        }, ],

    });

    $('.search-inp').on( 'keyup click', function () {   // For text boxes
        var i = $(this).attr('data-column');  // Getting column index
        var v = $(this).val();  // Getting search input value
        table.columns(i).search(v).draw();
    });
    $('.search-inp').on( 'change', function () {   // For select box
        var i = $(this).attr('data-column');
        var v = $(this).val();
        table.columns(i).search(v).draw();
    });
});

function reload_table() {
    table.ajax.reload(null, false); // Reload datatable ajax
}

and I have added this code to my datatable:

"fnServerParams": function (aoData) {
    aoData.push({name: "pid", value: '15'});
},

2 Answers 2

2

Option fnServerParams is for older version of jQuery DataTables 1.9. Since you're using 1.10, use ajax.data option instead as shown below:

 table = $('#table').DataTable({
        "processing": true, // Feature control the processing indicator.
        "serverSide": true, // Feature control DataTables' server-side processing mode.

        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "<?php echo site_url('admin/invite_instagrammers/GetInstagrammersData')?>",
            "type": "POST",
            "data": {
               "pid": "15"
            }
        },

        // ... skipped ...
Sign up to request clarification or add additional context in comments.

1 Comment

And as supplemental info, see this -> datatables.net/forums/discussion/28002/…
0

"data":{ "foo":"bar" }

is for static data parameters, if you want to send dynamic data let's say something in an input value please use this on

                "data": function ( d ) {
                    d.OrderNo =  $('#OrderNo').val();
                }

Comments

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.