Skip to content

Commit

Permalink
adab8a9ed0fcf8b77345ebc0ce76062bd350a358 Fix: Correct error when usin…
Browse files Browse the repository at this point in the history
…g scrolling and RowGroup - column sizing was incorrect

The "fixing" of sizes was reading the grouping row, which was incorrect

Sync to source repo @adab8a9ed0fcf8b77345ebc0ce76062bd350a358
  • Loading branch information
dtbuild committed Aug 19, 2024
1 parent b23e05c commit 360b562
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 27 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.1.4",
"last-sync": "08b0f7110addabcfd814a9215a18ced31e54a8f5"
"last-sync": "adab8a9ed0fcf8b77345ebc0ce76062bd350a358"
}
38 changes: 26 additions & 12 deletions js/dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -5226,21 +5226,35 @@
// is because of Responsive which might remove `col` elements, knocking the alignment
// of the indexes out.
if (settings.aiDisplay.length) {
// Get the column sizes from the first row in the table
var colSizes = table.children('tbody').eq(0).children('tr').eq(0).children('th, td').map(function (vis) {
return {
idx: _fnVisibleToColumnIndex(settings, vis),
width: $(this).outerWidth()
// Get the column sizes from the first row in the table. This should really be a
// [].find, but it wasn't supported in Chrome until Sept 2015, and DT has 10 year
// browser support
var firstTr = null;

for (i=0 ; i<settings.aiDisplay.length ; i++) {
var idx = settings.aiDisplay[i];

if (settings.aoData[idx].nTr) {
firstTr = settings.aoData[idx].nTr;
}
});
}

// Check against what the colgroup > col is set to and correct if needed
for (var i=0 ; i<colSizes.length ; i++) {
var colEl = settings.aoColumns[ colSizes[i].idx ].colEl[0];
var colWidth = colEl.style.width.replace('px', '');
if (firstTr) {
var colSizes = $(firstTr).children('th, td').map(function (vis) {
return {
idx: _fnVisibleToColumnIndex(settings, vis),
width: $(this).outerWidth()
}
});

if (colWidth !== colSizes[i].width) {
colEl.style.width = colSizes[i].width + 'px';
// Check against what the colgroup > col is set to and correct if needed
for (var i=0 ; i<colSizes.length ; i++) {
var colEl = settings.aoColumns[ colSizes[i].idx ].colEl[0];
var colWidth = colEl.style.width.replace('px', '');

if (colWidth !== colSizes[i].width) {
colEl.style.width = colSizes[i].width + 'px';
}
}
}
}
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.

38 changes: 26 additions & 12 deletions js/dataTables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5173,21 +5173,35 @@ function _fnScrollDraw ( settings )
// is because of Responsive which might remove `col` elements, knocking the alignment
// of the indexes out.
if (settings.aiDisplay.length) {
// Get the column sizes from the first row in the table
var colSizes = table.children('tbody').eq(0).children('tr').eq(0).children('th, td').map(function (vis) {
return {
idx: _fnVisibleToColumnIndex(settings, vis),
width: $(this).outerWidth()
// Get the column sizes from the first row in the table. This should really be a
// [].find, but it wasn't supported in Chrome until Sept 2015, and DT has 10 year
// browser support
var firstTr = null;

for (i=0 ; i<settings.aiDisplay.length ; i++) {
var idx = settings.aiDisplay[i];

if (settings.aoData[idx].nTr) {
firstTr = settings.aoData[idx].nTr;
}
});
}

// Check against what the colgroup > col is set to and correct if needed
for (var i=0 ; i<colSizes.length ; i++) {
var colEl = settings.aoColumns[ colSizes[i].idx ].colEl[0];
var colWidth = colEl.style.width.replace('px', '');
if (firstTr) {
var colSizes = $(firstTr).children('th, td').map(function (vis) {
return {
idx: _fnVisibleToColumnIndex(settings, vis),
width: $(this).outerWidth()
}
});

if (colWidth !== colSizes[i].width) {
colEl.style.width = colSizes[i].width + 'px';
// Check against what the colgroup > col is set to and correct if needed
for (var i=0 ; i<colSizes.length ; i++) {
var colEl = settings.aoColumns[ colSizes[i].idx ].colEl[0];
var colWidth = colEl.style.width.replace('px', '');

if (colWidth !== colSizes[i].width) {
colEl.style.width = colSizes[i].width + 'px';
}
}
}
}
Expand Down

0 comments on commit 360b562

Please sign in to comment.