fix(grid): preserve row selection during infinite-scroll append

This commit is contained in:
zipg authored and GitHub committed 2026-08-05 09:47:26 +08:00
1 parent ffaede31b9
commit 509a1530f6
3 files changed
+29 -3

No files matched your search

@@ -9,6 +9,11 @@ export interface DataGridScrollMetrics {
clientHeight: number;
}
export interface DataGridAppendResult {
rows: readonly unknown[];
appended_from_row_count?: number;
}
export function dataGridScrollPosition(top: number, left: number): DataGridScrollPosition {
return {
top: Math.max(0, top),
@@ -30,6 +35,11 @@ export function isDataGridNearScrollBottom(metrics: DataGridScrollMetrics, thres
return metrics.scrollHeight - metrics.scrollTop - metrics.clientHeight < threshold;
}
export function isDataGridPrefixAppend(previous: DataGridAppendResult | undefined, next: DataGridAppendResult): boolean {
if (!previous || next.appended_from_row_count !== previous.rows.length || next.rows.length < previous.rows.length) return false;
return previous.rows.every((row, index) => row === next.rows[index]);
}
export function isDataGridAtScrollBottom(metrics: DataGridScrollMetrics, tolerance = 1): boolean {
const maxScrollTop = Math.max(0, metrics.scrollHeight - metrics.clientHeight);
return maxScrollTop - metrics.scrollTop <= tolerance;