DataTable destroy is not clearing the table header sorting elements

DataTable destroy is not clearing the table header sorting elements

vahivahi Posts: 6Questions: 3Answers: 0
edited November 2020 in Free community support

Link to test case: https://jsfiddle.net/d8zywthg/

Description of problem:
Issue 1: I am initializing a DataTable and then destroying it. I noticed that the classes (eg: sorting_asc) and elements (eg: DataTables_sort_wrapper) added by the DataTable are not cleared from the table thead section when I call table.destroy(). Is this a bug or expected behavior ?

Issue 2: Also I noticed that if I initialize a DataTable and then destroy it and again initialize it, the DataTables_sort_wrapper in the table thead section is duplicated. So if I initialized the DataTable and destroyed it 5 times, you will notice that there are 5 instances of DataTables_sort_wrapper div element for each th. Please see the screenshot below. Any workaround for this?

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Yep, this is actually an old known issue (DD-71 for my reference), that's just been grazing in the backlog. We're making releases today, so we've put this onto the to-fix list, so it should be resolved by end of day. I'll report back here when it's progressed.

    Colin

  • vahivahi Posts: 6Questions: 3Answers: 0

    @colin Thanks for the quick update :)

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    I was a bit too quick - the release won't be today, it'll be Monday next week instead! Apologies for the inconvenience
    .
    Colin

  • vahivahi Posts: 6Questions: 3Answers: 0

    This is how I handled it for now

    $(document).on('destroy.dt', function (e, settings) {
    var sortIcon = $(settings.nTable.tHead).find('.DataTables_sort_icon');
    sortIcon.unwrap();
    sortIcon.remove();
    });

This discussion has been closed.