Table Headers from AJAX?

Table Headers from AJAX?

BusterenBusteren Posts: 52Questions: 17Answers: 4

Hi,
Been looking for this a bit now and can see that there is an older thread an older thread.

Just wondered if it is possible to change the table headers with an ajax call (using datatable) or if I just should do it with the API?
Say I have ajax data like this:

[
 { "name": "hello", "today": { "value": 1, "date": "2019"}}
]

and a table initialisation which is something like this:

$('#table').DataTable({
        ajax: {
            url: "/table/ajax/",
            type: "POST",
        },
        columns: [
            { data: "name" },
            { data: "today.value", name: "today.date"},
        ],
    });

Should I just check on complete/success and then redo the column headers?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @Busteren ,

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • BusterenBusteren Posts: 52Questions: 17Answers: 4

    Cheers, I have the headers in the HTML on initialisation, so I used the drawCallback and checked that the data had a length of 1 or more (there's data).

    If I got time, might look into adding something like that.

    Cheers again,

    Thor

This discussion has been closed.