Skip to content

Instantly share code, notes, and snippets.

@davidnormo
Last active April 11, 2024 13:03
Show Gist options
  • Save davidnormo/bc4af574629a73187ecd8c99ef44fc51 to your computer and use it in GitHub Desktop.
Save davidnormo/bc4af574629a73187ecd8c99ef44fc51 to your computer and use it in GitHub Desktop.
// from line 38520
StickyRowFeature.prototype.checkStickyRows = function () {
var _this = this;
var height = 0;
if (!this.gridOptionsService.isGroupRowsSticky()) {
return this.refreshNodesAndContainerHeight([], height);
}
var stickyRows = [];
var firstPixel = this.rowRenderer.getFirstVisibleVerticalPixel();
var addStickyRow = function (stickyRow) {
var _a, _b, _c;
stickyRows.push(stickyRow);
var lastChildBottom;
if (_this.isClientSide) {
var lastAncestor = stickyRow;
while (lastAncestor.expanded) {
if (lastAncestor.master) {
lastAncestor = lastAncestor.detailNode;
}
else if (lastAncestor.childrenAfterSort) {
// Tree Data will have `childrenAfterSort` without any nodes, but
// the current node will still be marked as expansible.
if (lastAncestor.childrenAfterSort.length === 0) {
break;
}
lastAncestor = last(lastAncestor.childrenAfterSort);
}
}
// ===== TRP fix =====
// The below code is handling the scenario where the `lastAncestor` in the group isn't rendered.
// This is the case in pivot mode when the bottom most row group is always collapsed.
// Before this fix, `lastAncestor.rowTop` is NaN causing an infinite loop as it's not
// able to find the bottom pixel of the last row in the group.
while (!lastAncestor.alreadyRendered) {
lastAncestor = lastAncestor.parent;
}
// ===== TRP fix =====
lastChildBottom = lastAncestor.rowTop + lastAncestor.rowHeight;
}
// if the rowModel is `serverSide` as only `clientSide` and `serverSide` create this feature.
else {
if (stickyRow.master) {
lastChildBottom = stickyRow.detailNode.rowTop + stickyRow.detailNode.rowHeight;
}
else {
var storeBounds = (_a = stickyRow.childStore) === null || _a === void 0 ? void 0 : _a.getStoreBounds();
lastChildBottom = ((_b = storeBounds === null || storeBounds === void 0 ? void 0 : storeBounds.heightPx) !== null && _b !== void 0 ? _b : 0) + ((_c = storeBounds === null || storeBounds === void 0 ? void 0 : storeBounds.topPx) !== null && _c !== void 0 ? _c : 0);
}
}
var stickRowBottom = firstPixel + height + stickyRow.rowHeight;
if (lastChildBottom < stickRowBottom) {
stickyRow.stickyRowTop = height + (lastChildBottom - stickRowBottom);
}
else {
stickyRow.stickyRowTop = height;
}
height = 0;
stickyRows.forEach(function (rowNode) {
var thisRowLastPx = rowNode.stickyRowTop + rowNode.rowHeight;
if (height < thisRowLastPx) {
height = thisRowLastPx;
}
});
};
while (true) {
var firstPixelAfterStickyRows = firstPixel + height;
var firstIndex = this.rowModel.getRowIndexAtPixel(firstPixelAfterStickyRows);
var firstRow = this.rowModel.getRow(firstIndex);
if (firstRow == null) {
break;
}
// only happens when pivoting, and we are showing root node
if (firstRow.level < 0) {
break;
}
var parents = [];
var p = firstRow.parent;
while (p.level >= 0) {
parents.push(p);
p = p.parent;
}
var firstMissingParent = parents.reverse().find(function (parent) { return stickyRows.indexOf(parent) < 0 && parent.displayed; });
if (firstMissingParent) {
addStickyRow(firstMissingParent);
continue;
}
// if first row is an open group, and practically shown, it needs
// to be stuck
if (firstRow.isExpandable() && firstRow.expanded && firstRow.rowTop < firstPixelAfterStickyRows) {
addStickyRow(firstRow);
continue;
}
break;
}
return this.refreshNodesAndContainerHeight(stickyRows, height);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment