@linzjs/step-ag-grid 14.2.0 → 14.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Grid.d.ts +5 -1
- package/dist/src/lui/timeoutHook.d.ts +6 -0
- package/dist/step-ag-grid.esm.js +89 -50
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +48 -10
- package/src/contexts/GridContextProvider.tsx +2 -3
- package/src/lui/timeoutHook.tsx +13 -0
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -14,6 +14,7 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "r
|
|
|
14
14
|
|
|
15
15
|
import { GridContext } from "../contexts/GridContext";
|
|
16
16
|
import { GridUpdatingContext } from "../contexts/GridUpdatingContext";
|
|
17
|
+
import { useIntervalHook } from "../lui/timeoutHook";
|
|
17
18
|
import { fnOrVar, isNotEmpty } from "../utils/util";
|
|
18
19
|
import { GridNoRowsOverlay } from "./GridNoRowsOverlay";
|
|
19
20
|
import { usePostSortRowsHook } from "./PostSortRowsHook";
|
|
@@ -34,6 +35,10 @@ export interface GridProps {
|
|
|
34
35
|
defaultColDef?: GridOptions["defaultColDef"];
|
|
35
36
|
columnDefs: ColDef[];
|
|
36
37
|
rowData: GridOptions["rowData"];
|
|
38
|
+
/**
|
|
39
|
+
* Whether select column is pinned. Defaults to "left".
|
|
40
|
+
*/
|
|
41
|
+
selectColumnPinned?: ColDef["pinned"];
|
|
37
42
|
noRowsOverlayText?: string;
|
|
38
43
|
postSortRows?: GridOptions["postSortRows"];
|
|
39
44
|
animateRows?: boolean;
|
|
@@ -76,7 +81,8 @@ export const Grid = ({
|
|
|
76
81
|
rowSelection = "multiple",
|
|
77
82
|
suppressColumnVirtualization = true,
|
|
78
83
|
theme = "ag-theme-alpine",
|
|
79
|
-
sizeColumns = "auto
|
|
84
|
+
sizeColumns = "auto",
|
|
85
|
+
selectColumnPinned = "left",
|
|
80
86
|
...params
|
|
81
87
|
}: GridProps): JSX.Element => {
|
|
82
88
|
const {
|
|
@@ -98,6 +104,8 @@ export const Grid = ({
|
|
|
98
104
|
} = useContext(GridContext);
|
|
99
105
|
const { checkUpdating, updatedDep, isUpdating } = useContext(GridUpdatingContext);
|
|
100
106
|
|
|
107
|
+
const gridDivRef = useRef<HTMLDivElement>(null);
|
|
108
|
+
|
|
101
109
|
const lastSelectedIds = useRef<number[]>([]);
|
|
102
110
|
const [staleGrid, setStaleGrid] = useState(false);
|
|
103
111
|
const postSortRows = usePostSortRowsHook({ setStaleGrid });
|
|
@@ -109,20 +117,26 @@ export const Grid = ({
|
|
|
109
117
|
*/
|
|
110
118
|
const hasSetContentSize = useRef(false);
|
|
111
119
|
const hasSetContentSizeEmpty = useRef(false);
|
|
120
|
+
const needsAutoSize = useRef(false);
|
|
112
121
|
|
|
113
122
|
const setInitialContentSize = useCallback(() => {
|
|
114
|
-
|
|
123
|
+
if (!gridDivRef.current?.clientWidth) {
|
|
124
|
+
// Don't resize grids if they are offscreen as it doesn't work.
|
|
125
|
+
needsAutoSize.current = true;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const skipHeader = sizeColumns === "auto-skip-headers" && !isEmpty(params.rowData);
|
|
115
129
|
if (sizeColumns === "auto" || skipHeader) {
|
|
116
130
|
const result = autoSizeColumns({ skipHeader, userSizedColIds: userSizedColIds.current });
|
|
117
131
|
if (isEmpty(params.rowData)) {
|
|
118
|
-
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
132
|
+
if (!hasSetContentSizeEmpty.current && result && !hasSetContentSize.current) {
|
|
119
133
|
hasSetContentSizeEmpty.current = true;
|
|
120
|
-
params.onContentSize &&
|
|
134
|
+
params.onContentSize && params.onContentSize(result);
|
|
121
135
|
}
|
|
122
136
|
} else {
|
|
123
|
-
if (!hasSetContentSize.current) {
|
|
137
|
+
if (result && !hasSetContentSize.current) {
|
|
124
138
|
hasSetContentSize.current = true;
|
|
125
|
-
params.onContentSize &&
|
|
139
|
+
params.onContentSize && params.onContentSize(result);
|
|
126
140
|
}
|
|
127
141
|
}
|
|
128
142
|
}
|
|
@@ -130,11 +144,22 @@ export const Grid = ({
|
|
|
130
144
|
if (sizeColumns !== "none") {
|
|
131
145
|
sizeColumnsToFit();
|
|
132
146
|
}
|
|
147
|
+
needsAutoSize.current = false;
|
|
133
148
|
}, [autoSizeColumns, params, sizeColumns, sizeColumnsToFit]);
|
|
134
149
|
|
|
135
150
|
/**
|
|
136
|
-
*
|
|
151
|
+
* Auto-size windows that had deferred auto-size
|
|
137
152
|
*/
|
|
153
|
+
useIntervalHook({
|
|
154
|
+
callback: () => {
|
|
155
|
+
if (needsAutoSize.current) {
|
|
156
|
+
needsAutoSize.current = false;
|
|
157
|
+
setInitialContentSize();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
timeoutMs: 1000,
|
|
161
|
+
});
|
|
162
|
+
|
|
138
163
|
const previousGridReady = useRef(gridReady);
|
|
139
164
|
useEffect(() => {
|
|
140
165
|
if (!previousGridReady.current && gridReady) {
|
|
@@ -266,6 +291,7 @@ export const Grid = ({
|
|
|
266
291
|
editable: false,
|
|
267
292
|
minWidth: 42,
|
|
268
293
|
maxWidth: 42,
|
|
294
|
+
pinned: selectColumnPinned,
|
|
269
295
|
headerComponentParams: {
|
|
270
296
|
exportable: false,
|
|
271
297
|
},
|
|
@@ -292,6 +318,7 @@ export const Grid = ({
|
|
|
292
318
|
params.selectable,
|
|
293
319
|
params.readOnly,
|
|
294
320
|
params.defaultColDef?.editable,
|
|
321
|
+
selectColumnPinned,
|
|
295
322
|
rowSelection,
|
|
296
323
|
clickSelectorCheckboxWhenContainingCellClicked,
|
|
297
324
|
]);
|
|
@@ -465,7 +492,12 @@ export const Grid = ({
|
|
|
465
492
|
// This auto-sizes based on updatingContext completing
|
|
466
493
|
colIdsEdited.current.add(colId);
|
|
467
494
|
// This auto-sizes immediately in case it was an in place update
|
|
468
|
-
!isUpdating() &&
|
|
495
|
+
!isUpdating() &&
|
|
496
|
+
autoSizeColumns({
|
|
497
|
+
skipHeader,
|
|
498
|
+
userSizedColIds: userSizedColIds.current,
|
|
499
|
+
colIds: [colId],
|
|
500
|
+
});
|
|
469
501
|
}
|
|
470
502
|
}
|
|
471
503
|
},
|
|
@@ -531,7 +563,7 @@ export const Grid = ({
|
|
|
531
563
|
gridReady && params.rowData && "Grid-ready",
|
|
532
564
|
)}
|
|
533
565
|
>
|
|
534
|
-
<div style={{ flex: 1 }}>
|
|
566
|
+
<div style={{ flex: 1 }} ref={gridDivRef}>
|
|
535
567
|
<AgGridReact
|
|
536
568
|
animateRows={params.animateRows}
|
|
537
569
|
rowClassRules={params.rowClassRules}
|
|
@@ -542,6 +574,9 @@ export const Grid = ({
|
|
|
542
574
|
onGridSizeChanged={onGridSizeChanged}
|
|
543
575
|
suppressColumnVirtualisation={suppressColumnVirtualization}
|
|
544
576
|
suppressClickEdit={true}
|
|
577
|
+
onColumnVisible={() => {
|
|
578
|
+
setInitialContentSize();
|
|
579
|
+
}}
|
|
545
580
|
onRowDataChanged={onRowDataChanged}
|
|
546
581
|
onCellKeyPress={onCellKeyPress}
|
|
547
582
|
onCellClicked={onCellClicked}
|
|
@@ -554,7 +589,10 @@ export const Grid = ({
|
|
|
554
589
|
columnDefs={columnDefsAdjusted}
|
|
555
590
|
rowData={params.rowData}
|
|
556
591
|
noRowsOverlayComponent={GridNoRowsOverlay}
|
|
557
|
-
noRowsOverlayComponentParams={{
|
|
592
|
+
noRowsOverlayComponentParams={{
|
|
593
|
+
rowData: params.rowData,
|
|
594
|
+
noRowsOverlayText: params.noRowsOverlayText,
|
|
595
|
+
}}
|
|
558
596
|
onModelUpdated={onModelUpdated}
|
|
559
597
|
onGridReady={onGridReady}
|
|
560
598
|
onSortChanged={ensureSelectedRowIsVisible}
|
|
@@ -352,7 +352,6 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
352
352
|
columnApi.autoSizeColumn(colId, skipHeader);
|
|
353
353
|
}
|
|
354
354
|
});
|
|
355
|
-
|
|
356
355
|
return {
|
|
357
356
|
width: sumBy(
|
|
358
357
|
columnApi.getColumnState().filter((col) => !col.hide),
|
|
@@ -538,12 +537,12 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
538
537
|
|
|
539
538
|
const addExternalFilter = (filter: GridFilterExternal<RowType>) => {
|
|
540
539
|
externalFilters.current.push(filter);
|
|
541
|
-
onFilterChanged();
|
|
540
|
+
onFilterChanged().then();
|
|
542
541
|
};
|
|
543
542
|
|
|
544
543
|
const removeExternalFilter = (filter: GridFilterExternal<RowType>) => {
|
|
545
544
|
remove(externalFilters.current, (v) => v === filter);
|
|
546
|
-
onFilterChanged();
|
|
545
|
+
onFilterChanged().then();
|
|
547
546
|
};
|
|
548
547
|
|
|
549
548
|
const isExternalFilterPresent = (): boolean => externalFilters.current.length > 0;
|
package/src/lui/timeoutHook.tsx
CHANGED
|
@@ -38,3 +38,16 @@ export const useTimeoutHook = () => {
|
|
|
38
38
|
|
|
39
39
|
return invoke;
|
|
40
40
|
};
|
|
41
|
+
|
|
42
|
+
interface IntervalHookProps {
|
|
43
|
+
timeoutMs: number;
|
|
44
|
+
callback: () => void;
|
|
45
|
+
}
|
|
46
|
+
export const useIntervalHook = ({ callback, timeoutMs }: IntervalHookProps) => {
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const interval = setInterval(callback, timeoutMs);
|
|
49
|
+
return () => {
|
|
50
|
+
clearInterval(interval);
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
};
|