How to generate dynamic columns based on the dataset
How to generate dynamic columns based on the dataset
althaf
Posts: 5Questions: 3Answers: 0
I need to generate dynamic columns based on the dataset. Some times my dataset has 3 columns and sometimes it has 5 columns based on the dropdown selection.
In that case how we can render the data table.
Below is my code for the dataset with 3 columns. How to use the same code for the dataset with 5 columns.
function RenderDataTable(dataset) {
var table = $('#dsexample').DataTable({
destroy: true,
data: dataset,
"orderClasses": false,
//fixedColumns: true,
columns: [
{
title: "Unique ID",
"width": "100"
},
{
title: "Level1",
"width": "200"
},
{
title: "Level2",
"width": "200"
}
]
})
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @althaf ,
Take a look at this example - here it's defining the columns in a variable which is then referenced in the table initialisation.
You could do the same - just create the array first with the number of columns that you want, whether that be 3 or 5 as you used in your example, then pass that into the table initialisation.
That should do it for you,
Cheers,
Colin
Great Helo Colin. Thanks. You save my day.