JSON array of arrays as datasource with column names in the first array
JSON array of arrays as datasource with column names in the first array
I have a json like this:
var dataSet =
[
[
"datetime",
"Service name",
" End time",
"details",
"status"
],
[
"2017-05-30T16:00:00.000Z",
"TV Service",
"2017-05-30T17:00:00.000Z",
[],
"ready"
]
The json is coming from querying an api from another project.
I want to use this as datasource in the datatable. Also I want to rearrange the column names in this order while omitting the details. I am using columns.title to generate the column names from a config file.
columns: [
{ title: "Service" }, --- this one is Service Name
{ title: "Scheduled start time" }, --- this one is datetime
{ title: "Scheduled end time" },
{ title: "Status" }
]
So far I have written it like this:
table.DataTable({
columns: [
{ title: "Service" },
{ title: "Scheduled start time" },
{ title: "Scheduled end time" },
{ title: "Status" }
],
data: dataSet
});
How to rearrange the order of the columns and also omit the first array which includes the column names so that it does not show up as data row in the table?
Answers
Found a way to rearrange the columns like this:
However the column names are still coming up in the table as a row. Is there any way to remove first array from the datasSet? Or should I just remove it manually and then push the data into DataTables?