how to populate column from a dynamic json data

how to populate column from a dynamic json data

zackelberryzackelberry Posts: 7Questions: 2Answers: 0

I have this header. ColumnB and ColumnC is dynamic, there can be more than two.
I have manage to create this on html. my problem is how can I bind the data on the datatable columns

$('#myTable').DataTable({
columns:??????????????????????????
})

This question has an accepted answers - jump to answer

Answers

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

    To DataTables, that would just be a standard five-column table. This section of the examples shows different data sources that you could use.

    Colin

  • zackelberryzackelberry Posts: 7Questions: 2Answers: 0
    edited January 2021

    thank you @Colin
    yeah I know that when it comes to DataTable it will be a five column Table. but like what i said. the columns are dynamic.it could have columnD with two subcolumns, 5 is the minimum. it can be 7, 9, 11. it depends on the user selection.

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

    Are you using data in the DOM, or does the user's selection trigger an ajax call?

    Colin

  • zackelberryzackelberry Posts: 7Questions: 2Answers: 0

    it triggers an ajax call. and the number of columns is depending on it.

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

    In that case, you would need to destroy the table and recreate it again, as you can't add columns dynamically. Kevin's example in this thread may help to get you going,

    Colin

  • zackelberryzackelberry Posts: 7Questions: 2Answers: 0

    thank you. just the way i wanted.

This discussion has been closed.