From c48ff6ca73854d2e90db4799087fba4f6f8ad32e Mon Sep 17 00:00:00 2001 From: melloware Date: Thu, 16 Jun 2022 08:53:06 -0400 Subject: [PATCH] Fix #2978/#2943: Datatable virtualscroller column resizing --- components/lib/datatable/DataTable.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/components/lib/datatable/DataTable.js b/components/lib/datatable/DataTable.js index 12fecd1828..d04d415f3d 100644 --- a/components/lib/datatable/DataTable.js +++ b/components/lib/datatable/DataTable.js @@ -24,6 +24,8 @@ export const DataTable = React.forwardRef((props, ref) => { const elementRef = React.useRef(null); const tableRef = React.useRef(null); const wrapperRef = React.useRef(null); + const bodyRef = React.useRef(null); + const frozenBodyRef = React.useRef(null); const reorderIndicatorUpRef = React.useRef(null); const reorderIndicatorDownRef = React.useRef(null); const colReorderIconWidth = React.useRef(null); @@ -495,8 +497,18 @@ export const DataTable = React.forwardRef((props, ref) => { } else if (props.columnResizeMode === 'expand') { const tableWidth = tableRef.current.offsetWidth + delta + 'px'; - tableRef.current.style.width = tableWidth; - tableRef.current.style.minWidth = tableWidth; + const updateTableWidth = (el) => { + !!el && (el.style.width = el.style.minWidth = tableWidth); + } + updateTableWidth(tableRef.current); + + if (!isVirtualScrollerDisabled()) { + updateTableWidth(bodyRef.current); + updateTableWidth(frozenBodyRef.current); + if (wrapperRef.current) { + DomHandler.findSingle(wrapperRef.current, '.p-virtualscroller-content').style.width = tableWidth; + } + } resizeTableCells(newColumnWidth); } @@ -1367,7 +1379,7 @@ export const DataTable = React.forwardRef((props, ref) => { const { rows, columns, contentRef, className } = options; const frozenBody = props.frozenValue && ( - { isVirtualScrollerDisabled={true} /> ); const body = ( -