Skip to content

Commit c3c38d2

Browse files
authored
Merge pull request #4261 from yancat160/fix/datatable-horizontal-scroll-on-overflow
fix: keep DataGrid tables inside their card with horizontal scroll (eg sessions)
2 parents c20aede + 06caccb commit c3c38d2

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

src/components/common/DataGrid.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,67 @@ export function DataGrid({
6262
const child = data ? (typeof children === 'function' ? children(data) : children) : null;
6363

6464
return (
65+
<Column gap="4" minHeight="300px">
66+
{allowSearch && (
67+
<Row alignItems="center" justifyContent="space-between" wrap="wrap" gap>
68+
<SearchField
69+
value={search}
70+
onSearch={handleSearch}
71+
delay={searchDelay || DEFAULT_SEARCH_DELAY}
72+
autoFocus={autoFocus}
73+
placeholder={t(labels.search)}
74+
/>
75+
{renderActions?.()}
76+
</Row>
77+
)}
78+
<LoadingPanel
79+
data={data?.data}
80+
isLoading={isLoading}
81+
isFetching={isFetching}
82+
error={error}
83+
renderEmpty={renderEmpty}
84+
>
85+
{data && (
86+
<>
87+
{/*
88+
Wrap the table in a horizontally scrollable container. The
89+
react-zen DataTable lays its columns out on a CSS Grid with
90+
fixed pixel widths, so the sum of column widths becomes the
91+
table's max-content and propagates up through the surrounding
92+
flex chain into the Tabs grid track, pinning every ancestor
93+
wider than the viewport on small screens. overflow-x: auto on
94+
its own does not break that chain because the wrapper still
95+
stretches to its parent's width. Setting display: grid with
96+
grid-template-columns: minmax(0, 1fr) gives the wrapper an
97+
explicit 1fr column that resolves to the available space,
98+
caps its own intrinsic width, and lets overflow-x: auto
99+
kick in so the user can scroll the columns horizontally
100+
instead of having the card overflow off screen.
101+
*/}
102+
<div
103+
style={{
104+
display: 'grid',
105+
gridTemplateColumns: 'minmax(0, 1fr)',
106+
overflowX: 'auto',
107+
}}
108+
>
109+
{isValidElement(child)
110+
? cloneElement(child as ReactElement<any>, { displayMode })
111+
: child}
112+
</div>
113+
{showPager && (
114+
<Row marginTop="6">
115+
<Pager
116+
page={data.page}
117+
pageSize={data.pageSize}
118+
count={data.count}
119+
onPageChange={handlePageChange}
120+
/>
121+
</Row>
122+
)}
123+
</>
124+
)}
125+
</LoadingPanel>
65126
<Column gap="4" minHeight="300px" justifyContent="space-between">
66127
<Column gap="4">
67128
{allowSearch && (

0 commit comments

Comments
 (0)