I need to read from a JSON object (not via ajax) and dynamically generate/update a table's content and headers. I've been searching and trying for hours now and can't find a solution. Any help would be highly appreciated.
Something like this to generate column headers from an array would be a start:
function generateStatsObject (selectedCropsAndYearsArray) { // eg: ["Barley-2016", "Barley-2017", "Potato-2016"]
panelTableData.destroy();
panelTableData = $('#table_panels').DataTable({
columns: [
{title:[selectedCropsAndYearsArray]}
]
});
panelTableData.draw();
}
Later I'd like to change selectedCropsAndYearsArray to an object, such as [{title: "Barley-2016", value: "2234"}] and append key:value pairs. title should used column header and value as the actual data.
Cheers!