Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fnServerParams is not a function

I'm using jQuery DataTables and I want to add parameter to Ajax call in my table definition.

But it gives error when I attempt to use fnServerParams. Here is my table and method that I use to add parameter:

var tableObjects = $("#logTable").DataTable({
        "bProcessing": false,
        "bServerSide": true,
        "sAjaxSource": "../../Controller/DashboardController.php5",
        "aoColumns": [
            {"mDataProp": "clientname" ,"sortable": false },
            {"mDataProp": "clientip"},
            {"mDataProp": "url","sortable": false },
            {"mDataProp": "respsize"},
            {"mDataProp": "loggingdate"},
            {"mDataProp": "reqmethod"},
            {"mDataProp": "resultcode"},
            {"mDataProp": "duration"},
            {"mDataProp": "hierarchycode"}
        ],
        "fnServerParams": function (val1,val2 ) {
            if((val1)&&(val2))
                aoData.push({"name":val1,value:val2})
        },
        "fnServerData": function (sSource, aoData, fnCallback){
            aoData.push({"name":"tablename","value":"dashboard"});
            $.ajax({
                "dataType": "json",
                "contentType": "application/json; charset=utf-8",
                "type": "GET",
                "url": sSource,
                "data": aoData,
                "success": function(result){
                    fnCallback(result);
                },
                error: function (xhr, textStatus, error){
                    }
                }
            });
        }
})

And I add parameters with this function call:

$("#slcFilter").on("change",function(){
   tableObjects.fnServerParams("paramname","value");
   //"tableObjects.fnServerParams is not a function" but why ?
});

1 Answers

In DataTables 1.10 naming convention has changed, see API for more information.

You need to initialize your table as $("#logTable").dataTable() with lower case d to get access to previous version API or with $("#logTable").DataTable() with upper case D to get access to newer API.

Also there is no fnServerParams() function, it's an option fnServerParams that should be defined as follows:

"fnServerParams": function (aoData) {
    aoData.push( { "name": "select", "value": $("#slcFilter").val() } );      
},

See my answer to your other similar question.

like image 124
Gyrocode.com Avatar answered Mar 27 '26 21:03

Gyrocode.com