@linzjs/step-ag-grid 14.1.1 → 14.1.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/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": "14.1.1",
5
+ "version": "14.1.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -91,12 +91,25 @@ export const Grid = ({
91
91
  const [staleGrid, setStaleGrid] = useState(false);
92
92
  const postSortRows = usePostSortRowsHook({ setStaleGrid });
93
93
 
94
+ const hasSetContentSize = useRef(false);
95
+ const hasSetContentSizeEmpty = useRef(false);
96
+
94
97
  const setInitialContentSize = useCallback(() => {
95
- const skipHeaders = sizeColumns === "auto-skip-headers";
96
- if (sizeColumns === "auto" || skipHeaders) {
97
- // If we aren't skipping headers and there's no data, then don't skip headers
98
- const result = autoSizeAllColumns({ skipHeader: skipHeaders && !isEmpty(params.rowData) });
99
- params.onContentSize && result && params.onContentSize(result);
98
+ if (
99
+ (!isEmpty(params.rowData) && !hasSetContentSize.current) ||
100
+ (isEmpty(params.rowData) && !hasSetContentSizeEmpty.current)
101
+ ) {
102
+ const skipHeaders = sizeColumns === "auto-skip-headers";
103
+ if (sizeColumns === "auto" || skipHeaders) {
104
+ // If we aren't skipping headers and there's no data, then don't skip headers
105
+ const result = autoSizeAllColumns({ skipHeader: skipHeaders && !isEmpty(params.rowData) });
106
+ if (isEmpty(params.rowData)) {
107
+ hasSetContentSizeEmpty.current = true;
108
+ } else {
109
+ hasSetContentSize.current = true;
110
+ }
111
+ params.onContentSize && result && params.onContentSize(result);
112
+ }
100
113
  }
101
114
 
102
115
  if (sizeColumns !== "none") {
@@ -269,6 +282,8 @@ export const Grid = ({
269
282
  */
270
283
  const previousRowDataLength = useRef(0);
271
284
  useEffect(() => {
285
+ if (!gridReady) return;
286
+
272
287
  const length = params.rowData?.length ?? 0;
273
288
  if (previousRowDataLength.current !== length) {
274
289
  if (previousRowDataLength.current === 0 && length > 0) {
@@ -276,7 +291,7 @@ export const Grid = ({
276
291
  }
277
292
  previousRowDataLength.current = length;
278
293
  }
279
- }, [params.rowData?.length, setInitialContentSize]);
294
+ }, [gridReady, params.rowData?.length, setInitialContentSize]);
280
295
 
281
296
  const onModelUpdated = useCallback((event: ModelUpdatedEvent) => {
282
297
  event.api.getDisplayedRowCount() === 0 ? event.api.showNoRowsOverlay() : event.api.hideOverlay();
@@ -350,10 +365,6 @@ export const Grid = ({
350
365
  [startCellEditing],
351
366
  );
352
367
 
353
- const onGridSizeChanged = useCallback(() => {
354
- sizeColumns !== "none" && sizeColumnsToFit();
355
- }, [sizeColumns, sizeColumnsToFit]);
356
-
357
368
  /**
358
369
  * Once the grid has auto-sized we want to run fit to fit the grid in its container,
359
370
  * but we don't want the non-flex auto-sized columns to "fit" size, so suppressSizeToFit is set to true.
@@ -385,7 +396,7 @@ export const Grid = ({
385
396
  suppressRowClickSelection={true}
386
397
  rowSelection={rowSelection}
387
398
  suppressBrowserResizeObserver={true}
388
- onGridSizeChanged={onGridSizeChanged}
399
+ onGridSizeChanged={setInitialContentSize}
389
400
  suppressColumnVirtualisation={suppressColumnVirtualization}
390
401
  suppressClickEdit={true}
391
402
  onCellKeyPress={onCellKeyPress}
@@ -348,7 +348,12 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
348
348
  ({ skipHeader }): { width: number } | null => {
349
349
  if (columnApi) {
350
350
  columnApi.autoSizeAllColumns(skipHeader);
351
- return { width: sumBy(columnApi.getColumnState(), "width") };
351
+ return {
352
+ width: sumBy(
353
+ columnApi.getColumnState().filter((col) => col.hide !== true),
354
+ "width",
355
+ ),
356
+ };
352
357
  }
353
358
  return null;
354
359
  },