@linzjs/step-ag-grid 29.11.1 → 29.11.2
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/README.md +1 -1
- package/dist/src/contexts/GridContextProvider.d.ts +4 -1
- package/dist/step-ag-grid.cjs +32 -45
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +30 -46
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +25 -67
- package/src/contexts/GridContextProvider.tsx +31 -26
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +5 -7
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
GetRowIdParams,
|
|
15
15
|
GridOptions,
|
|
16
16
|
GridReadyEvent,
|
|
17
|
-
IColumnLimit,
|
|
18
17
|
ModelUpdatedEvent,
|
|
19
18
|
ModuleRegistry,
|
|
20
19
|
RowClickedEvent,
|
|
@@ -203,7 +202,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
203
202
|
const hasSetContentSizeEmpty = useRef(false);
|
|
204
203
|
const needsAutoSize = useRef(true);
|
|
205
204
|
|
|
206
|
-
const requiresInitialSizeToFitRef = useRef(false);
|
|
207
205
|
const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
|
|
208
206
|
const prevRowsVisibleRef = useRef(false);
|
|
209
207
|
const setInitialContentSize = useCallback(() => {
|
|
@@ -250,14 +248,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
250
248
|
// We don't do this callback if we have previously had row data, or have already called back for empty
|
|
251
249
|
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
252
250
|
hasSetContentSizeEmpty.current = true;
|
|
253
|
-
requiresInitialSizeToFitRef.current = true;
|
|
254
251
|
params.onContentSize?.(autoSizeResult);
|
|
255
252
|
}
|
|
256
253
|
} else if (gridRendered === 'rows-visible') {
|
|
257
254
|
// we have rows now so callback grid size
|
|
258
255
|
if (!hasSetContentSize.current) {
|
|
259
256
|
hasSetContentSize.current = true;
|
|
260
|
-
requiresInitialSizeToFitRef.current = true;
|
|
261
257
|
params.onContentSize?.(autoSizeResult);
|
|
262
258
|
}
|
|
263
259
|
} else {
|
|
@@ -265,6 +261,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
265
261
|
console.error('Unknown value returned from hasGridRendered');
|
|
266
262
|
}
|
|
267
263
|
} else {
|
|
264
|
+
console.log('sizeColumnsToFit 3');
|
|
268
265
|
sizeColumnsToFit();
|
|
269
266
|
}
|
|
270
267
|
|
|
@@ -607,9 +604,10 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
607
604
|
* When cell editing has completed the colId as needing auto-sizing
|
|
608
605
|
*/
|
|
609
606
|
useEffect(() => {
|
|
610
|
-
if (lastUpdatedDep.current === updatedDep)
|
|
607
|
+
if (lastUpdatedDep.current === updatedDep) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
611
610
|
lastUpdatedDep.current = updatedDep;
|
|
612
|
-
|
|
613
611
|
const colIds = updatingCols();
|
|
614
612
|
// Updating possibly completed
|
|
615
613
|
if (isEmpty(colIds)) {
|
|
@@ -648,32 +646,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
648
646
|
prevLoading.current = newLoading;
|
|
649
647
|
}, [params.loading, rowData, showNoRowsOverlay]);
|
|
650
648
|
|
|
651
|
-
/**
|
|
652
|
-
* Resize columns to fit if required on window/container resize
|
|
653
|
-
*/
|
|
654
|
-
const onGridResize = useCallback(
|
|
655
|
-
(event: AgGridEvent<TData>) => {
|
|
656
|
-
if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
if (sizeColumns !== 'none') {
|
|
660
|
-
// Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
|
|
661
|
-
// Double click column resize handle to reset this behaviour
|
|
662
|
-
const columnLimits = [
|
|
663
|
-
...userSizedColIds.current.entries().map(
|
|
664
|
-
([c, w]): IColumnLimit => ({
|
|
665
|
-
key: c,
|
|
666
|
-
minWidth: w,
|
|
667
|
-
maxWidth: w,
|
|
668
|
-
}),
|
|
669
|
-
),
|
|
670
|
-
];
|
|
671
|
-
defer(() => event.api.sizeColumnsToFit({ columnLimits }));
|
|
672
|
-
}
|
|
673
|
-
},
|
|
674
|
-
[sizeColumns],
|
|
675
|
-
);
|
|
676
|
-
|
|
677
649
|
/**
|
|
678
650
|
* Set of column I'd's that are prevented from auto-sizing as they are user set
|
|
679
651
|
*/
|
|
@@ -682,33 +654,29 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
682
654
|
/**
|
|
683
655
|
* Lock/unlock column width on user edit/reset.
|
|
684
656
|
*/
|
|
685
|
-
const onColumnResized = useCallback(
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
userSizedColIds.current.set(colId, width);
|
|
699
|
-
const colDef = e.column?.getColDef();
|
|
657
|
+
const onColumnResized = useCallback((e: ColumnResizedEvent) => {
|
|
658
|
+
const colId = e.column?.getColId();
|
|
659
|
+
if (colId == null) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const width = e.column?.getActualWidth();
|
|
663
|
+
if (width == null) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
switch (e.source) {
|
|
667
|
+
case 'uiColumnResized':
|
|
668
|
+
userSizedColIds.current.set(colId, width);
|
|
669
|
+
/*const colDef = e.column?.getColDef();
|
|
700
670
|
if (!colDef?.flex) {
|
|
701
671
|
onGridResize(e);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
[onGridResize],
|
|
711
|
-
);
|
|
672
|
+
}*/
|
|
673
|
+
break;
|
|
674
|
+
case 'autosizeColumns':
|
|
675
|
+
userSizedColIds.current.delete(colId);
|
|
676
|
+
//onGridResize(e);
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
}, []);
|
|
712
680
|
|
|
713
681
|
const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
|
|
714
682
|
|
|
@@ -909,20 +877,10 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
909
877
|
}
|
|
910
878
|
: undefined
|
|
911
879
|
}
|
|
912
|
-
onDisplayedColumnsChanged={() => {
|
|
913
|
-
// This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
|
|
914
|
-
if (requiresInitialSizeToFitRef.current) {
|
|
915
|
-
requiresInitialSizeToFitRef.current = false;
|
|
916
|
-
delay(() => {
|
|
917
|
-
sizeColumnsToFit();
|
|
918
|
-
}, 200);
|
|
919
|
-
}
|
|
920
|
-
}}
|
|
921
880
|
rowHeight={rowHeight}
|
|
922
881
|
animateRows={params.animateRows ?? false}
|
|
923
882
|
rowClassRules={params.rowClassRules}
|
|
924
883
|
getRowId={getRowId}
|
|
925
|
-
onGridSizeChanged={onGridResize}
|
|
926
884
|
suppressColumnVirtualisation={suppressColumnVirtualization}
|
|
927
885
|
suppressClickEdit={true}
|
|
928
886
|
onColumnVisible={setInitialContentSize}
|
|
@@ -10,20 +10,7 @@ import {
|
|
|
10
10
|
RowNode,
|
|
11
11
|
} from 'ag-grid-community';
|
|
12
12
|
import debounce from 'debounce-promise';
|
|
13
|
-
import {
|
|
14
|
-
compact,
|
|
15
|
-
defer,
|
|
16
|
-
delay,
|
|
17
|
-
difference,
|
|
18
|
-
filter,
|
|
19
|
-
isEmpty,
|
|
20
|
-
last,
|
|
21
|
-
partition,
|
|
22
|
-
pull,
|
|
23
|
-
remove,
|
|
24
|
-
sortBy,
|
|
25
|
-
sumBy,
|
|
26
|
-
} from 'lodash-es';
|
|
13
|
+
import { compact, defer, delay, difference, filter, isEmpty, last, pull, remove, sortBy, sumBy } from 'lodash-es';
|
|
27
14
|
import { PropsWithChildren, ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
28
15
|
|
|
29
16
|
import { ColDefT, GridBaseRow } from '../components';
|
|
@@ -34,8 +21,9 @@ import { waitForCondition } from '../utils/waitForCondition';
|
|
|
34
21
|
import { AutoSizeColumnsProps, AutoSizeColumnsResult, GridContext, GridFilterExternal } from './GridContext';
|
|
35
22
|
import { GridUpdatingContext } from './GridUpdatingContext';
|
|
36
23
|
|
|
37
|
-
const colStateId = (colState: ColumnState) => colState.colId;
|
|
38
|
-
const colStateFlexed = (colState: ColumnState) => !!colState.flex;
|
|
24
|
+
export const colStateId = (colState: ColumnState) => colState.colId;
|
|
25
|
+
export const colStateFlexed = (colState: ColumnState) => !!colState.flex;
|
|
26
|
+
export const colStateNotFlexed = (colState: ColumnState) => !colState.flex;
|
|
39
27
|
|
|
40
28
|
/**
|
|
41
29
|
* Context for AgGrid operations.
|
|
@@ -451,27 +439,44 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
451
439
|
return null;
|
|
452
440
|
}
|
|
453
441
|
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
|
|
454
|
-
const colStates = gridApi.getColumnState();
|
|
455
442
|
|
|
456
|
-
const
|
|
457
|
-
const
|
|
458
|
-
return (
|
|
459
|
-
|
|
460
|
-
|
|
443
|
+
const getVisibleColStates = () => {
|
|
444
|
+
const colStates = gridApi.getColumnState();
|
|
445
|
+
return colStates.filter((colState) => {
|
|
446
|
+
const colId = colState.colId;
|
|
447
|
+
return (isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
|
|
451
|
+
const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
|
|
452
|
+
|
|
461
453
|
// If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
|
|
454
|
+
let flexColumns = getFlexColStates();
|
|
455
|
+
let width = 0;
|
|
462
456
|
if (!isEmpty(flexColumns)) {
|
|
463
457
|
gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
|
|
458
|
+
const flexColumnIds = flexColumns.map(colStateId);
|
|
459
|
+
flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
|
|
460
|
+
width += sumBy(
|
|
461
|
+
flexColumns.filter((col) => !col.hide),
|
|
462
|
+
'width',
|
|
463
|
+
);
|
|
464
464
|
gridApi.resetColumnState();
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
+
let nonFlexColumns = getNonFlexColStates();
|
|
467
468
|
if (!isEmpty(nonFlexColumns)) {
|
|
468
469
|
gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
|
|
470
|
+
const nonFlexColumnIds = nonFlexColumns.map(colStateId);
|
|
471
|
+
nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
|
|
472
|
+
width += sumBy(
|
|
473
|
+
nonFlexColumns.filter((col) => !col.hide),
|
|
474
|
+
'width',
|
|
475
|
+
);
|
|
469
476
|
}
|
|
477
|
+
|
|
470
478
|
return {
|
|
471
|
-
width
|
|
472
|
-
gridApi.getColumnState().filter((col) => !col.hide),
|
|
473
|
-
'width',
|
|
474
|
-
),
|
|
479
|
+
width,
|
|
475
480
|
};
|
|
476
481
|
},
|
|
477
482
|
[gridApi],
|
|
@@ -19,13 +19,11 @@ export default {
|
|
|
19
19
|
},
|
|
20
20
|
decorators: [
|
|
21
21
|
(Story) => (
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
</GridUpdatingContextProvider>
|
|
28
|
-
</div>
|
|
22
|
+
<GridUpdatingContextProvider>
|
|
23
|
+
<GridContextProvider>
|
|
24
|
+
<Story />
|
|
25
|
+
</GridContextProvider>
|
|
26
|
+
</GridUpdatingContextProvider>
|
|
29
27
|
),
|
|
30
28
|
],
|
|
31
29
|
} as Meta<typeof Grid>;
|