Skip to content

Commit

Permalink
Fix #2978/#2943: Datatable virtualscroller column resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jun 16, 2022
1 parent 46e5ae6 commit c48ff6c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions components/lib/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1367,7 +1379,7 @@ export const DataTable = React.forwardRef((props, ref) => {
const { rows, columns, contentRef, className } = options;

const frozenBody = props.frozenValue && (
<TableBody value={props.frozenValue} className="p-datatable-frozen-tbody" frozenRow
<TableBody ref={frozenBodyRef} value={props.frozenValue} className="p-datatable-frozen-tbody" frozenRow
tableProps={props} tableSelector={attributeSelectorState} columns={columns} selectionModeInColumn={selectionModeInColumn}
first={first} editingMeta={editingMetaState} onEditingMetaChange={onEditingMetaChange} tabIndex={props.tabIndex}
onRowClick={props.onRowClick} onRowDoubleClick={props.onRowDoubleClick} onCellClick={props.onCellClick}
Expand All @@ -1387,7 +1399,7 @@ export const DataTable = React.forwardRef((props, ref) => {
isVirtualScrollerDisabled={true} />
);
const body = (
<TableBody value={dataToRender(rows)} className={className} empty={empty} frozenRow={false}
<TableBody ref={bodyRef} value={dataToRender(rows)} className={className} empty={empty} frozenRow={false}
tableProps={props} tableSelector={attributeSelectorState} columns={columns} selectionModeInColumn={selectionModeInColumn}
first={first} editingMeta={editingMetaState} onEditingMetaChange={onEditingMetaChange} tabIndex={props.tabIndex}
onRowClick={props.onRowClick} onRowDoubleClick={props.onRowDoubleClick} onCellClick={props.onCellClick}
Expand Down

0 comments on commit c48ff6c

Please sign in to comment.