How to load data source using api query?

How to load data source using api query?

balaram26balaram26 Posts: 2Questions: 1Answers: 0

I access data through certain API's. HOw to use the data table server side scripting for this purpose? I have tested both the options of trying to provide ajaxurl as API query address directly or use a PHP to get the data from API query and then provide php as the ajaxurl. Both the API and php return JSON data type,yet they fail. Are there any complete working examples to show this?

Answers

  • tangerinetangerine Posts: 3,349Questions: 37Answers: 394

    Your methods should work if coded correctly. What do you mean by "they fail"?

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    What DataTables sends to the server and what it expects back are documented here. If your APIs on the server-side handle that information and return the expected JSON, it should just work.

    Allan

  • balaram26balaram26 Posts: 2Questions: 1Answers: 0

    Hi ,here is what my code looks like-

    $('#table').DataTable( {
                    "processing": true,
                    "serverSide": true,
                    "ajax": "http://xxxxx",
                    "columns": [
                        { "data": "id" },
                        { "data": "type" },
                        { "data": "path" }                    
                    ]
     } );
    

    my json looks like-

    [
    {"id":1,"type":"Engineered","pid":0,"path":"Engineered"},
    {"id":2,"type":"Biogas plant","pid":1,"path":"Engineered"},
    ...
    

    The above js is added to the HTML page and the the api aldready provides with the above described JSON as the result for the given API query. Should anything has to be changed for the tables to be loaded ?? The **"ajax": "http://xxxxx" ** contains the API query which is present from the server side [i was told that its handled java program].

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin
    edited April 2018

    The JSON being returned from the server does not contain the information that DataTables requires for server-side processing. You need to include the paging and search information in the returned JSON as documented.

    Allan

This discussion has been closed.