Skip to content

Commit

Permalink
FIX: NPE on getColumnState (#458)
Browse files Browse the repository at this point in the history
FIX: NPE on getColumnState (#458)
  • Loading branch information
matttdawson authored May 21, 2024
1 parent 4af1efb commit e5a1e5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ export const Grid = ({
const skipHeader = sizeColumns === "auto-skip-headers" && gridRendered === "rows-visible";
if (sizeColumns === "auto" || skipHeader) {
const result = autoSizeColumns({ skipHeader, userSizedColIds: userSizedColIds.current, includeFlex: true });
if (!result) {
needsAutoSize.current = true;
return;
}
if (gridRendered === "empty") {
if (!hasSetContentSizeEmpty.current && result && !hasSetContentSize.current) {
hasSetContentSizeEmpty.current = true;
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/GridContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
*/
const autoSizeColumns = useCallback(
({ skipHeader, colIds, userSizedColIds, includeFlex }: AutoSizeColumnsProps = {}): AutoSizeColumnsResult => {
if (!gridApi) return null;
if (!gridApi || !gridApi.getColumnState()) return null;
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
const colsToResize = gridApi.getColumnState().filter((colState) => {
const colsToResize = gridApi.getColumnState()?.filter?.((colState) => {
const colId = colState.colId;
return (
(isEmpty(colIdsSet) || colIdsSet.has(colId)) &&
Expand Down

0 comments on commit e5a1e5e

Please sign in to comment.