Skip to content

Commit

Permalink
Fix Datatables initialization issues (#3746)
Browse files Browse the repository at this point in the history
It's possible there is some race condition in Datatables being
registered in the global space and the default module being executed.
This new call is the (new) documented method of settings defaults.


While I was at it I fixed floating scroll:
The update to Datatables v2 had the internals of the table scrambled.
It's now actually a lot cleaner but the target for the floating scroll
did change!
  • Loading branch information
chrisvanrun authored Dec 12, 2024
1 parent cc9642f commit c1c4c35
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/grandchallenge/core/static/js/datatables.defaults.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$.extend(true, DataTable.defaults, {
$.extend($.fn.dataTable.defaults, {
scrollX: true,
language: {
paginate: {
Expand All @@ -10,6 +10,13 @@ $.extend(true, DataTable.defaults, {
});

$(document).on("init.dt", () => {
// Set up floating scroll, note that the target class only shows up when scrollX is set to true
$(".dataTables_scrollBody").floatingScroll();
const element = $(".dt-scroll-body");

if (element.length === 0) {
console.warn(
"Warning: Element for floating-scroll attachment could not be located",
);
}

element.floatingScroll();
});

0 comments on commit c1c4c35

Please sign in to comment.