Server side processing jquery data table with dynamic data instead of file

Server side processing jquery data table with dynamic data instead of file

e.raj2587@gmail.come.raj2587@gmail.com Posts: 1Questions: 1Answers: 0
edited July 2014 in Free community support

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

  • darms21darms21 Posts: 5Questions: 1Answers: 0

    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.

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394
    edited July 2014

    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.

  • darms21darms21 Posts: 5Questions: 1Answers: 0

    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.

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    Am I correct in assuming the AJAX tab from the example is a JSON response from the server side script?

    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.

  • darms21darms21 Posts: 5Questions: 1Answers: 0

    There is NO console output error being reported by Chrome when the invalid JSON response is displayed.

This discussion has been closed.