jqueryajaxdatatables

jquery datatable ajax property


I want to populate jquery data table from web service using ajax property of data table, so I can still do client side processing.

I am thinking something like this:

$('#example').dataTable( 
{ "ajax": { "url": "../.NET webservice", "type": "POST" } } );

If I can then I need to return data from .NET web service as an array of array ?

e.g.

{ "data": [ [ "Tom", "Utah", "Koala", "Kite"],

["Bob", "New Mexico", "Kangaroo", "Kite"] ] }

Can you please confirm ? I do not see any good examples that show how to do this.

Thanks in advance...


Solution

  • you can use following ways for server data

    $("#example").dataTable({
        "sAjaxSource" : "../.NET",
        "fnServerData" : function(sSource, aoData, fnCallback) {
             aoData.push({
                        "name" : "param1",
                        "value" : val1
                    }, {
                        "name" : "param2",
                        "value" : val2
                    });
             $.getJSON(sSource, aoData, function(json) {
                            fnCallback(json)
                        });
                    }
    });
    

    Or you can use:-

    $("#example").dataTable({
        "sAjaxSource" : "../.NET?param1=value&pram2=value2"
    });
    

    only point is response should be in json from server.