generate columns with data from ajax response

generate columns with data from ajax response

broadbearbroadbear Posts: 1Questions: 1Answers: 0

Is it possible to generate the table columns with data inside the ajax response? I've seen people wrap the dataTable() call in an ajax request and, if successful, initialize the table with the json data returned from the request, but this avoids the 'Loading' message. I want to be able to set the 'ajax' property so ajax calls are managed by the DataTable instance, and read the column names from the ajax response. Is this possible?

Ex.

$('#form_table').dataTable({
   'ajax': 'rest/forms/123',
   'columns': '***where can I get this data from?***'
});

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    edited October 2014

    I would also like to know if you can do this. I am trying to make my server side processing as dynamic as possible. I already have the columns defined on the back end, so I don't see a reason to define them again in the javascript. I can easily add columns to the response, but I don't know how to access that data.

    $('#form_table').dataTable({ 'ajax': 'rest/forms/123', 'columns': 'ajaxResponseData.columns' //what is the ajax response variable name? });

  • john_ljohn_l Posts: 45Questions: 0Answers: 12

    I've only done this using my own separate ajax call to fetch a complete data package from the server (including column definitions and row data), and then initializing the table once the call is complete. It's easy enough to put up your own loading indicator.

This discussion has been closed.