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",
} );
} );
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)
} );
}
} );
} );
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With