Issue on dynamic table header rendering

Issue on dynamic table header rendering

EraiarasuEraiarasu Posts: 5Questions: 1Answers: 0

I am using angular datatable(dtOptions) and rendering table based on the dropdown selection. Headers and data inside table is dynamic. When I change table header it will display the header along with additional header of previously loaded. I am using the below code to load header and data.

Thanks in advance
Erai.

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited October 2023

    You will probably need to ask on a forum that supports Angular Datatables. Angular Datatables is a library that wraps the use of Datatables. I don't believe there is anyone on this forum that knows much about Angular Datatables.

    Looks like you are using destroy to allow reinitializing Datatables with a new config. You might need to use the destroy() API instead and clear the HTML table. See the second example in the docs. You will need to reference the Angular Datatables docs to learn how to do this in your environment.

    Kevin

  • EraiarasuEraiarasu Posts: 5Questions: 1Answers: 0
    edited October 2023

    dtInstance.destroy() clears only the table's data not header. I want to clear data as well as header too.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    .destroy(true) will remove the table from the document. If instead you wanted to keep the table, but have it empty:

    table.destroy();
    $('#myTable').empty();
    

    Or if not using jQuery, loop over while the childNodes.length of #myTable is not empty and remove the child.

    Allan

Sign In or Register to comment.