Server side processing jquery data table with dynamic data instead of file
Server side processing jquery data table with dynamic data instead of file
I am using jquery datatable to displaying data in tabular format with extended functionality in many of the projects. One of the problems I am currently facing is about the large data size. Browser get hangs down displaying large amount of rows in the table and also take more initialization/load time. I want to get the data from server side.
I got Sever Side Processing and Ajax option which incorporate this functionality. But I don't know how to get JSON data on the fly instead of fetching it from a server file.
I'm using:
$('#example').dataTable( {
"ajax": {
"url": "data.json",
"dataSrc": function ( json ) {
for ( var i=0, ien=json.length ; i<ien ; i++ ) {
json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
}
return json;
}
}
} );
Here "url": "data.json" is not getting me. I want to have url pointing to server side web method which returns JSON data. It would be helpful if anybody shares a complete example of server side datatable with dynamic data which is not related to file storage. Thanks in advance.
Answers
I too would greatly benefit from having a more explicit example. The provided example (linked above) leaves so much for interpretation....which I've not been able to grasp unfortunately.
Why can't you follow the basic server-side example?
http://datatables.net/examples/data_sources/server_side.html
@e.raj2587 : your initialisation code is not using serverSide.
To recap how I have followed the example provided:
- I've copied the javascript tab as is
- copied the HTML tab with a slight alteration to account for the columns in my table
- added a reference to the CSS page
- copied the server side script with a slight alteration to the column array to account for the columns in my table and added the correct username, password, server.
Am I correct in assuming the AJAX tab from the example is a JSON response from the server side script?
I have meticulously followed the example and still I am getting an invalid JSON response.
Yes.
The example works, so your own code must be in error somewhere. An "invalid JSON" error means just that. Check your console output to see what it looks like.
There is NO console output error being reported by Chrome when the invalid JSON response is displayed.