Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery DataTables plugin - sAjaxSource

I get my data from the asp.net web service and I was wondering whether there is a way to pass on that data (in json formar straight from the web service) into the DataTables object. I would like to do something like:

$(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "http://localhost/WebService/GetData",
    } );
} );
like image 974
sarsnake Avatar asked Dec 23 '22 06:12

sarsnake


2 Answers

Yes you can do that. Is this what you mean?... pass a data to a server?

$(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "../examples_support/server_processing.php",
        "fnServerData": function ( sSource, aoData, fnCallback ) {
            /* Add some extra data to the sender */
            aoData.push( { "name": "more_data", "value": "my_value" } ); // this line will give additional data to the server...
            $.getJSON( sSource, aoData, function (json) { 
                /* Do whatever additional processing you want on the callback, then tell DataTables */
                fnCallback(json)
            } );
        }
    } );
} );
like image 107
Reigel Avatar answered Dec 26 '22 18:12

Reigel


Here you can find one article about using DataTables with ASP.NET MVC Integrating jQuery DataTables with ASP.NET MVC.

Hope this could help you. There are few thing that can help you (model class for accessing DataTables parameters and class for direct serialization int the JSON). It makes code little bit cleaner.

Regards

like image 36
Jovan Avatar answered Dec 26 '22 17:12

Jovan