@linzjs/step-ag-grid 29.2.3 → 29.2.4
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 +0 -1
- package/dist/src/components/Grid.d.ts +5 -1
- package/dist/src/components/GridCell.d.ts +1 -0
- package/dist/src/contexts/GridContext.d.ts +2 -2
- package/dist/step-ag-grid.cjs +8 -4
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +9 -5
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Grid.tsx +13 -2
- package/src/components/GridCell.tsx +1 -0
- package/src/contexts/GridContext.tsx +2 -2
- package/src/contexts/GridContextProvider.tsx +9 -5
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -3
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@linzjs/step-ag-grid",
|
|
3
3
|
"repository": "github:linz/step-ag-grid.git",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "29.2.
|
|
5
|
+
"version": "29.2.4",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"aggrid",
|
|
8
8
|
"ag-grid",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@chromatic-com/storybook": "^4.1.1",
|
|
84
84
|
"@linzjs/lui": "^23.11.1",
|
|
85
85
|
"@linzjs/style": "^5.4.0",
|
|
86
|
-
"@linzjs/windows": "^5.
|
|
86
|
+
"@linzjs/windows": "^5.6.0",
|
|
87
87
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
88
88
|
"@rollup/plugin-json": "^6.1.0",
|
|
89
89
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
package/src/components/Grid.tsx
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from 'ag-grid-community';
|
|
28
28
|
import { AgGridReact } from 'ag-grid-react';
|
|
29
29
|
import clsx from 'clsx';
|
|
30
|
-
import { defer, difference, isEmpty, last, omit, xorBy } from 'lodash-es';
|
|
30
|
+
import { defer, difference, isEmpty, last, omit, sum, xorBy } from 'lodash-es';
|
|
31
31
|
import { ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
32
32
|
import { useInterval } from 'usehooks-ts';
|
|
33
33
|
|
|
@@ -35,6 +35,7 @@ import { useGridContext } from '../contexts/GridContext';
|
|
|
35
35
|
import { GridUpdatingContext } from '../contexts/GridUpdatingContext';
|
|
36
36
|
import { fnOrVar, isNotEmpty } from '../utils/util';
|
|
37
37
|
import { clickInputWhenContainingCellClicked } from './clickInputWhenContainingCellClicked';
|
|
38
|
+
import { ColDefT } from './GridCell';
|
|
38
39
|
import { GridHeaderSelect } from './gridHeader';
|
|
39
40
|
import { GridContextMenuComponent, useGridContextMenu } from './gridHook';
|
|
40
41
|
import { GridNoRowsOverlay } from './GridNoRowsOverlay';
|
|
@@ -99,6 +100,10 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
|
|
|
99
100
|
* If you want to stretch to container width if width is greater than the container add a flex column.
|
|
100
101
|
*/
|
|
101
102
|
sizeColumns?: 'fit' | 'auto' | 'auto-skip-headers' | 'none';
|
|
103
|
+
/**
|
|
104
|
+
* On first don't return a content size larger than this.
|
|
105
|
+
*/
|
|
106
|
+
maxInitialWidth?: number;
|
|
102
107
|
/**
|
|
103
108
|
* When pressing tab whilst editing the grid will select and edit the next cell if available.
|
|
104
109
|
* Once the last cell to edit closes this callback is called.
|
|
@@ -145,6 +150,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
145
150
|
rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40,
|
|
146
151
|
selectable,
|
|
147
152
|
onCellFocused: paramsOnCellFocused,
|
|
153
|
+
maxInitialWidth,
|
|
148
154
|
...params
|
|
149
155
|
}: GridProps<TData>): ReactElement => {
|
|
150
156
|
const {
|
|
@@ -215,6 +221,11 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
215
221
|
needsAutoSize.current = true;
|
|
216
222
|
return;
|
|
217
223
|
}
|
|
224
|
+
// Default max intial width is 256x initial visible column count, max of 80% window width
|
|
225
|
+
const maxWidth =
|
|
226
|
+
maxInitialWidth ||
|
|
227
|
+
sum(params.columnDefs.map((c: ColDefT<TData>) => (!(c as any).hide ? c.maxInitialWidth || 128 : 0)));
|
|
228
|
+
result.width = Math.min(result.width, maxWidth);
|
|
218
229
|
if (gridRendered === 'empty') {
|
|
219
230
|
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
220
231
|
hasSetContentSizeEmpty.current = true;
|
|
@@ -241,7 +252,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
241
252
|
}
|
|
242
253
|
setAutoSized(true);
|
|
243
254
|
needsAutoSize.current = false;
|
|
244
|
-
}, [autoSizeColumns, gridRenderState, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
255
|
+
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
245
256
|
|
|
246
257
|
const lastOwnerDocumentRef = useRef<Document>();
|
|
247
258
|
const wasVisibleRef = useRef(false);
|
|
@@ -71,6 +71,7 @@ export interface ColDefT<TData extends GridBaseRow, ValueType = any> extends Col
|
|
|
71
71
|
editable?: boolean | EditableCallback<TData, ValueType>;
|
|
72
72
|
valueGetter?: string | ValueGetterFunc<TData, ValueType>;
|
|
73
73
|
valueFormatter?: string | ValueFormatterFunc<TData, ValueType>;
|
|
74
|
+
maxInitialWidth?: number;
|
|
74
75
|
cellRenderer?:
|
|
75
76
|
| ((props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined)
|
|
76
77
|
| string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColDef, GridApi, IRowNode } from 'ag-grid-community';
|
|
1
|
+
import { ColDef, GridApi, IRowNode, ISizeColumnsToFitParams } from 'ag-grid-community';
|
|
2
2
|
import { CsvExportParams } from 'ag-grid-community';
|
|
3
3
|
import { createContext, useContext } from 'react';
|
|
4
4
|
|
|
@@ -47,7 +47,7 @@ export interface GridContextType<TData extends GridBaseRow> {
|
|
|
47
47
|
ensureSelectedRowIsVisible: () => void;
|
|
48
48
|
getFirstRowId: () => number;
|
|
49
49
|
autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult;
|
|
50
|
-
sizeColumnsToFit: () => void;
|
|
50
|
+
sizeColumnsToFit: (paramsOrGridWidth?: ISizeColumnsToFitParams) => void;
|
|
51
51
|
startCellEditing: ({ rowId, colId }: StartCellEditingProps) => Promise<void>;
|
|
52
52
|
// Restores the previous focus after cell editing
|
|
53
53
|
resetFocusedCellAfterCellEditing: () => void;
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CsvExportParams,
|
|
5
5
|
GridApi,
|
|
6
6
|
IRowNode,
|
|
7
|
+
ISizeColumnsToFitParams,
|
|
7
8
|
ProcessCellForExportParams,
|
|
8
9
|
RowNode,
|
|
9
10
|
} from 'ag-grid-community';
|
|
@@ -455,11 +456,14 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
455
456
|
/**
|
|
456
457
|
* Resize columns to fit container
|
|
457
458
|
*/
|
|
458
|
-
const sizeColumnsToFit = useCallback(
|
|
459
|
-
|
|
460
|
-
gridApi
|
|
461
|
-
|
|
462
|
-
|
|
459
|
+
const sizeColumnsToFit = useCallback(
|
|
460
|
+
(paramsOrGridWidth?: ISizeColumnsToFitParams): void => {
|
|
461
|
+
if (gridApi && !gridApi?.isDestroyed()) {
|
|
462
|
+
gridApi.sizeColumnsToFit(paramsOrGridWidth);
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
[gridApi],
|
|
466
|
+
);
|
|
463
467
|
|
|
464
468
|
/**
|
|
465
469
|
*
|
package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx
CHANGED
|
@@ -71,7 +71,7 @@ interface ITestRow {
|
|
|
71
71
|
// Note: Resize can only be used from within the panel content.
|
|
72
72
|
export const PanelContentsWithResize = () => {
|
|
73
73
|
// This is the first important bit
|
|
74
|
-
const {
|
|
74
|
+
const { initialResizePanel } = useContext(PanelContext);
|
|
75
75
|
|
|
76
76
|
const columnDefs: ColDefT<ITestRow>[] = useMemo(
|
|
77
77
|
() => [
|
|
@@ -151,7 +151,13 @@ export const PanelContentsWithResize = () => {
|
|
|
151
151
|
const [rowData] = useState([
|
|
152
152
|
/* Your grid row data */
|
|
153
153
|
/* exclude */
|
|
154
|
-
{
|
|
154
|
+
{
|
|
155
|
+
id: 1000,
|
|
156
|
+
position: 'Tester',
|
|
157
|
+
age: 30,
|
|
158
|
+
desc: 'Tests application',
|
|
159
|
+
dd: '1',
|
|
160
|
+
},
|
|
155
161
|
{ id: 1001, position: 'Developer', age: 12, desc: 'Develops application', dd: '2' },
|
|
156
162
|
{ id: 1002, position: 'Manager', age: 65, desc: 'Manages', dd: '3' },
|
|
157
163
|
/* exclude */
|
|
@@ -161,7 +167,12 @@ export const PanelContentsWithResize = () => {
|
|
|
161
167
|
<GridUpdatingContextProvider>
|
|
162
168
|
<GridContextProvider>
|
|
163
169
|
<GridWrapper>
|
|
164
|
-
<Grid
|
|
170
|
+
<Grid
|
|
171
|
+
columnDefs={columnDefs}
|
|
172
|
+
rowData={rowData}
|
|
173
|
+
onContentSize={initialResizePanel}
|
|
174
|
+
sizeColumns={'auto-skip-headers'}
|
|
175
|
+
/>
|
|
165
176
|
</GridWrapper>
|
|
166
177
|
</GridContextProvider>
|
|
167
178
|
</GridUpdatingContextProvider>
|