Skip to content

Commit

Permalink
e58b21197e4895ea4dfada639e8483d3acb82ec9 Fix: -api destroy() wasn't…
Browse files Browse the repository at this point in the history
… removing the extra markup used by DataTables for headers and sorting

Fix: `-api destroy()` wasn't removing automatic column classes
Fix: `-api destroy()` wasn't removing attributes that had been added to the header cells.

https://datatables.net/forums/discussion/80456

Sync to source repo @e58b21197e4895ea4dfada639e8483d3acb82ec9
  • Loading branch information
dtbuild committed Jan 29, 2025
1 parent 24b1d98 commit 24e7189
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
],
"src-repo": "http://github.com/DataTables/DataTablesSrc",
"last-tag": "2.2.1",
"last-sync": "5775734c93eb8f1b82c590673ab82d20deeca69f"
"last-sync": "e58b21197e4895ea4dfada639e8483d3acb82ec9"
}
19 changes: 18 additions & 1 deletion js/dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -9908,20 +9908,37 @@
jqTable.append( tfoot );
}

// Clean up the header
$(thead).find('span.dt-column-order').remove();
$(thead).find('span.dt-column-title').each(function () {
var title = $(this).html();
$(this).parent().append(title);
$(this).remove();
});

settings.colgroup.remove();

settings.aaSorting = [];
settings.aaSortingFixed = [];
_fnSortingClasses( settings );

$(jqTable).find('th, td').removeClass(
$.map(DataTable.ext.type.className, function (v) {
return v;
}).join(' ')
);

$('th, td', thead)
.removeClass(
orderClasses.none + ' ' +
orderClasses.canAsc + ' ' +
orderClasses.canDesc + ' ' +
orderClasses.isAsc + ' ' +
orderClasses.isDesc
)
.css('width', '');
.css('width', '')
.removeAttr('data-dt-column')
.removeAttr('aria-sort');

// Add the TR elements back into the table in their original order
jqTbody.children().detach();
Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dataTables.min.mjs

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion js/dataTables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9873,20 +9873,37 @@ _api_register( 'destroy()', function ( remove ) {
jqTable.append( tfoot );
}

// Clean up the header
$(thead).find('span.dt-column-order').remove();
$(thead).find('span.dt-column-title').each(function () {
var title = $(this).html();
$(this).parent().append(title);
$(this).remove();
});

settings.colgroup.remove();

settings.aaSorting = [];
settings.aaSortingFixed = [];
_fnSortingClasses( settings );

$(jqTable).find('th, td').removeClass(
$.map(DataTable.ext.type.className, function (v) {
return v;
}).join(' ')
);

$('th, td', thead)
.removeClass(
orderClasses.none + ' ' +
orderClasses.canAsc + ' ' +
orderClasses.canDesc + ' ' +
orderClasses.isAsc + ' ' +
orderClasses.isDesc
)
.css('width', '');
.css('width', '')
.removeAttr('data-dt-column')
.removeAttr('aria-sort');

// Add the TR elements back into the table in their original order
jqTbody.children().detach();
Expand Down

0 comments on commit 24e7189

Please sign in to comment.