primereact
primereact copied to clipboard
DataTable: Column width changes while scrolling if the content width is varied
Describe the bug
As discussed previously here, there's no obvious/immediate way to make the column width to have fixed width (but still adjustable on drag and drop) if the content of the cells have different widths. It's very easy to reproduce on an infinite scroll DataTable while scrolling down.
Reproducer
https://stackblitz.com/edit/mhjis6?file=src%2Fservice%2FCarService.jsx
PrimeReact version
10.6.6
React version
17.x
Language
TypeScript
Build / Runtime
Create React App (CRA)
Browser(s)
No response
Steps to reproduce the behavior
- Go to the stackblitz project or clone the project with infinite scroll and make a column content with longer width
- Scroll down and see the column width change/jump
Expected behavior
I understand that this behaviour can be beneficial for some but it would be useful to have a way to make the column width fixed regardless its content
Yep not all datatable features are compatible with other features so this may be a difficult one to make everyone happy but still work properly.
@gabrielhpugliese in case that could help you in any way:
How I'm doing it
<DataTable
virtualScrollerOptions={{ itemSize: 46, className: "flex flex-auto align-items-start" }}
dataKey="id"
value={...}
className="flex-auto overflow-hidden"
filters={filters}
size="small"
selectionMode="multiple"
selection={...}
onSelectionChange={handleSelectionChange}
stripedRows
resizableColumns
columnResizeMode="expand"
reorderableColumns
dragSelection
scrollable
scrollHeight="flex"
sortMode="multiple"
multiSortMeta={multiSortMeta}
removableSort
loading={loading}
tableStyle={{ tableLayout: 'fixed', flex: '1 1 auto' }}
>
<Column selectionMode="multiple" headerStyle={{ minWidth: "40px", maxWidth: "40px", width: "40px" }} reorderable={false} resizeable={false}/>
{visibleColumns.map((col, index) => (
<Column
key={`anyKey_${col.field}`}
field={col.field}
header={col.header}
sortable={col.sortable}
body={col.body}
headerStyle={col.headerStyle}
pt={{
bodyCell: { className: "text-ellipsis" },
headerTitle: { className: "text-ellipsis" },
...col.pt
}}
resizeable={col.resizeable ?? true}
/>
))}
</DataTable>