Is it posibble to dynamically add columns settings for a datatable

Is it posibble to dynamically add columns settings for a datatable

SherilSheril Posts: 4Questions: 2Answers: 0

columns: [
{ title: "ID" },
{ title: "Name" },
{ title: "Employee ID" },
{ title: "Designation" },
{ title: "Location" }
]

Can we make this dynamic so that I can dynamically bind data to the datatable

Answers

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    Don't know what you mean by "data". If you mean columns the answer is no, if you mean rows the answer is yes. Just use the search function and search for rows().add() etc.

  • SherilSheril Posts: 4Questions: 2Answers: 0

    It woked for me

    colsObj should be dynamically generated using the logic

    jQuery(document).ready(function() {
    var dataObject =eval('[{"COLUMNS":['+colsObj+']}]');
    var columns = [];
    $('#example').dataTable({
    "data": dataObject[0].DATA,
    "columns": dataObject[0].COLUMNS
    });
    });

    and in the columns section I used the below code
    columns:dataObject[0].COLUMNS
    settings

This discussion has been closed.