diff --git a/components/lib/datatable/DataTable.js b/components/lib/datatable/DataTable.js index 7f9c57320a..a2fb96a679 100644 --- a/components/lib/datatable/DataTable.js +++ b/components/lib/datatable/DataTable.js @@ -1,6 +1,5 @@ import * as React from 'react'; -import PrimeReact, { FilterMatchMode, FilterOperator, FilterService } from '../api/Api'; -import { PrimeReactContext } from '../api/Api'; +import PrimeReact, { FilterMatchMode, FilterOperator, FilterService, PrimeReactContext } from '../api/Api'; import { ColumnBase } from '../column/ColumnBase'; import { useEventListener, useMountEffect, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; import { ArrowDownIcon } from '../icons/arrowdown'; @@ -1340,7 +1339,10 @@ export const DataTable = React.forwardRef((inProps, ref) => { }; useMountEffect(() => { - attributeSelector.current = UniqueComponentId(); + if (elementRef.current) { + attributeSelector.current = UniqueComponentId(); + elementRef.current.setAttribute(attributeSelector.current, ''); + } //setFiltersState(cloneFilters(props.filters)); // Github #4248 setD_filtersState(cloneFilters(props.filters)); @@ -1355,8 +1357,6 @@ export const DataTable = React.forwardRef((inProps, ref) => { }); useUpdateEffect(() => { - elementRef.current.setAttribute(attributeSelector.current, ''); - if (props.responsiveLayout === 'stack' && !props.scrollable) { createResponsiveStyle(); }