How to access the data loaded by 'ajax'-parameter

How to access the data loaded by 'ajax'-parameter

OenselOensel Posts: 19Questions: 4Answers: 1

In my Datatables < 1.10 I used to send some informations for my table with only one ajax-call:

    $.getJSON(ajaxUrl, function(data) 
    {   
        oTable = $('#myTable').dataTable(
        {
            "iDisplayLength":   data.iDisplayLength,
            "aaSorting":        data.aaSorting,
            "aaData":           data.aaData,
            "aoColumns":        data.aoColumns
        });
    });

This worked very fine and my table creatin was very dynamic.

Now I want to use the 'ajax' parameter in initialisation like this:

    $('#myTable').dataTable(
    {   
        "ajax":         ajaxUrl,  
        "pageLength":   data.iDisplayLength,
        "order":        data.aaSorting,
        "columns":      data.aoColumns,
        "ordering":     data.sort
    }); 

But I don't know how to access my json-objects aaSorting, aaColumns ...

Do you have any ideas ?

Replies

  • OenselOensel Posts: 19Questions: 4Answers: 1

    Some additions:
    'page.len' and the 'order' is now working, when I call it in 'initComplete'

        $('#myTable').DataTable().page.len($('#myTable').DataTable().ajax.json().iDisplayLength);
        $('#myTable').DataTable().order($('#myTable').DataTable().ajax.json().aaSorting);       
        $('#myTable').DataTable().draw();
    

    But my problem still is, that I don't know how to set the column-headers and I didn't find an option enable/disalbe ordering for all columns by a simple API-call.

  • allanallan Posts: 61,826Questions: 1Answers: 10,131 Site admin

    There is no option to load anything but data using DataTables' ajax option at the moment. In future I might add the option to load configuration that way as well, but currently you would need to either do it the way you used to or with the API as in your second post.

    Allan

This discussion has been closed.