Skip to content

Commit ece5c59

Browse files
r0b1ngjulivan
authored andcommitted
chore: virtual scrolling rework (no sticky)
1 parent af81eec commit ece5c59

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

packages/modules/data-widgets/src/themesource/datawidgets/web/_datagrid.scss

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,24 @@ $root: ".widget-datagrid";
520520
margin: 0 auto;
521521
}
522522

523-
:where(.widget-datagrid-grid.infinite-loading) {
523+
.infinite-loading.widget-datagrid-grid-body {
524+
// when virtual scroll is enabled we make area that holds rows scrollable
525+
// (while the area that holds column headers still stays in place)
524526
overflow-y: auto;
525527
}
526528

527-
:where(.infinite-loading .widget-datagrid-grid-head .th) {
528-
position: sticky;
529-
z-index: 1;
529+
.widget-datagrid-grid-head,
530+
.widget-datagrid-grid-body {
531+
// this element has to position their children (columns or headers)
532+
// as grid and have those aligned with the parent grid
533+
display: grid;
534+
// this property makes sure we align our own grid columns
535+
// to the columns defined in the global grid
536+
grid-template-columns: subgrid;
537+
538+
// ensure that we cover all columns of original top level grid
539+
// so our own columns get aligned with the parent
540+
grid-column: 1 / -1;
530541
}
531542

532543
:where(#{$root}-paging-bottom) {

packages/pluggableWidgets/datagrid-web/src/components/Grid.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
import classNames from "classnames";
22
import { createElement, JSX, ReactElement } from "react";
3-
import { PaginationEnum } from "../../typings/DatagridProps";
4-
import { useInfiniteControl } from "@mendix/widget-plugin-grid/components/InfiniteBody";
53

64
type P = Omit<JSX.IntrinsicElements["div"], "role" | "ref">;
75

86
export interface GridProps extends P {
9-
paginationType: PaginationEnum;
107
className?: string;
11-
hasMoreItems: boolean;
12-
setPage?: (update: (page: number) => number) => void;
138
}
149

1510
export function Grid(props: GridProps): ReactElement {
16-
const { className, style, paginationType, hasMoreItems, setPage, children, ...rest } = props;
17-
const isInfinite = paginationType === "virtualScrolling";
18-
const [trackScrolling, bodySize, containerRef] = useInfiniteControl({
19-
hasMoreItems,
20-
isInfinite,
21-
setPage
22-
});
11+
const { className, style, children, ...rest } = props;
2312

2413
return (
25-
<div
26-
className={classNames("widget-datagrid-grid table", { "infinite-loading": isInfinite }, className)}
27-
role="grid"
28-
{...rest}
29-
ref={containerRef}
30-
style={isInfinite && bodySize > 0 ? { ...style, maxHeight: bodySize } : style}
31-
onScroll={isInfinite ? trackScrolling : undefined}
32-
>
14+
<div className={classNames("widget-datagrid-grid table", className)} role="grid" style={style} {...rest}>
3315
{children}
3416
</div>
3517
);

packages/pluggableWidgets/datagrid-web/src/components/GridBody.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import classNames from "classnames";
22
import { createElement, Fragment, ReactElement } from "react";
3-
import { LoadingTypeEnum } from "../../typings/DatagridProps";
3+
import { LoadingTypeEnum, PaginationEnum } from "../../typings/DatagridProps";
44
import { SpinnerLoader } from "./loader/SpinnerLoader";
55
import { RowSkeletonLoader } from "./loader/RowSkeletonLoader";
6+
import { useInfiniteControl } from "@mendix/widget-plugin-grid/components/InfiniteBody";
67

78
interface Props {
89
className?: string;
@@ -14,10 +15,20 @@ interface Props {
1415
columnsSize: number;
1516
rowsSize: number;
1617
pageSize: number;
18+
pagination: PaginationEnum;
19+
hasMoreItems: boolean;
20+
setPage?: (update: (page: number) => number) => void;
1721
}
1822

1923
export function GridBody(props: Props): ReactElement {
20-
const { children } = props;
24+
const { children, pagination, hasMoreItems, setPage } = props;
25+
26+
const isInfinite = pagination === "virtualScrolling";
27+
const [trackScrolling, bodySize, containerRef] = useInfiniteControl({
28+
hasMoreItems,
29+
isInfinite,
30+
setPage
31+
});
2132

2233
const content = (): React.ReactElement => {
2334
if (props.isFirstLoad) {
@@ -32,7 +43,17 @@ export function GridBody(props: Props): ReactElement {
3243
};
3344

3445
return (
35-
<div className={classNames("widget-datagrid-grid-body table-content", props.className)} role="rowgroup">
46+
<div
47+
className={classNames(
48+
"widget-datagrid-grid-body table-content",
49+
{ "infinite-loading": isInfinite },
50+
props.className
51+
)}
52+
style={isInfinite && bodySize > 0 ? { maxHeight: `${bodySize}px` } : {}}
53+
role="rowgroup"
54+
ref={containerRef}
55+
onScroll={isInfinite ? trackScrolling : undefined}
56+
>
3657
{content()}
3758
</div>
3859
);

packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
166166
<Grid
167167
aria-multiselectable={selectionEnabled ? selectActionHelper.selectionType === "Multi" : undefined}
168168
style={cssGridStyles}
169-
setPage={setPage}
170-
paginationType={paginationType}
171-
hasMoreItems={hasMoreItems}
172169
>
173170
<GridHeader
174171
availableColumns={props.availableColumns}
@@ -195,6 +192,9 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
195192
columnsSize={visibleColumns.length}
196193
rowsSize={rows.length}
197194
pageSize={pageSize}
195+
pagination={props.paginationType}
196+
hasMoreItems={hasMoreItems}
197+
setPage={setPage}
198198
>
199199
<RowsRenderer
200200
preview={props.preview ?? false}

0 commit comments

Comments
 (0)