Skip to content

Commit 81370de

Browse files
committed
fix: go back to the fill css grid and fall back to detached header with calculated layout if needed
1 parent 2de7df6 commit 81370de

3 files changed

Lines changed: 61 additions & 19 deletions

File tree

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

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -524,27 +524,54 @@ $root: ".widget-datagrid";
524524
}
525525
}
526526

527+
// styles for browsers that don't support subgrid
528+
// if the browser doesn't support subgrid
529+
// fall back header an body the contents and apply grid template to the table
530+
.widget-datagrid-grid.table {
531+
grid-template-columns: var(--widgets-grid-template-columns);
532+
}
533+
.widget-datagrid-grid-body,
527534
.widget-datagrid-grid-head {
528-
display: grid;
529-
min-width: 0;
530-
531-
// this head is not part of the grid, so it has dedicated column template --widgets-grid-template-columns-head
532-
// but it might not be available at the initial render, so we use template from the grid --widgets-grid-template-columns
533-
// using template from the grid might to misalignment from the grid itself,
534-
// but in practice:
535-
// - grid has no data at that moment, so misalignment is not visible.
536-
// - as soon as the grid itself gets rendered --widgets-grid-template-columns-head gets calculated
537-
// and everything looks like it should.
538-
grid-template-columns: var(--widgets-grid-template-columns-head, var(--widgets-grid-template-columns));
535+
display: contents;
539536
}
540537

541-
.widget-datagrid-grid-body {
542-
// this element has to position their children (columns or headers)
543-
// as grid and have those aligned with the parent grid
544-
display: grid;
545-
// this property makes sure we align our own grid columns
546-
// to the columns defined in the global grid
547-
grid-template-columns: var(--widgets-grid-template-columns);
538+
// styles for modern browsers
539+
@supports (grid-template-rows: subgrid) {
540+
.widget-datagrid-grid.table:not([data-has-scroll-x="true"]) {
541+
grid-template-columns: var(--widgets-grid-template-columns);
542+
.widget-datagrid-grid-body,
543+
.widget-datagrid-grid-head {
544+
display: grid;
545+
min-width: 0;
546+
547+
// this property makes sure we align our own grid columns
548+
// to the columns defined in the global grid
549+
grid-template-columns: subgrid;
550+
551+
// ensure that we cover all columns of original top level grid
552+
// so our own columns get aligned with the parent
553+
grid-column: 1 / -1;
554+
}
555+
}
556+
557+
.widget-datagrid-grid.table[data-has-scroll-x="true"] {
558+
// reset the columns defined on table level
559+
// header and body will define their own instead
560+
// this is needed to make body horizontally scrollable
561+
grid-template-columns: initial;
562+
.widget-datagrid-grid-head {
563+
display: grid;
564+
min-width: 0;
565+
566+
grid-template-columns: var(--widgets-grid-template-columns-head, var(--widgets-grid-template-columns));
567+
}
568+
569+
.widget-datagrid-grid-body {
570+
display: grid;
571+
572+
grid-template-columns: var(--widgets-grid-template-columns);
573+
}
574+
}
548575
}
549576

550577
.grid-mock-header {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ export function MockHeader(): ReactNode {
88
const resizeCallback = useCallback<ResizeObserverCallback>(
99
entries => {
1010
const container = entries[0].target.parentElement!;
11+
12+
const gridContainer = container.closest<HTMLDivElement>(".table");
13+
const gridBody = container.closest<HTMLDivElement>(".table-content");
14+
if (gridContainer && gridBody) {
15+
if (gridContainer.dataset.hasScrollX === "true") {
16+
if (gridBody.scrollWidth <= gridBody.clientWidth) {
17+
delete gridContainer.dataset.hasScrollX;
18+
}
19+
} else {
20+
if (gridContainer.scrollWidth > gridContainer.clientWidth) {
21+
gridContainer.dataset.hasScrollX = "true";
22+
}
23+
}
24+
}
25+
1126
const sizes = new Map<string, number>();
1227
container.querySelectorAll<HTMLDivElement>("[data-column-id]").forEach(c => {
1328
const columnId = c.dataset.columnId;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export function Widget(props: { onExportCancel?: () => void }): ReactElement {
2626
<SelectAllBar />
2727
<RefreshStatus />
2828
<GridBody>
29-
<MockHeader />
3029
<RowsRenderer />
30+
<MockHeader />
3131
<EmptyPlaceholder />
3232
</GridBody>
3333
</Grid>

0 commit comments

Comments
 (0)