如何在反应表中计算并设置默认柱宽度?
我正在尝试动态设置列宽度,以便列宽的总和占据了表的整个宽度。我有一个具有动态宽度的反应表分量(需要其父宽度的100%),将宽度划分为列。长度并设置以下内容:
const defaultColumn = useMemo(
() => ({
width: columnWidth > 0 ? columnWidth : 150,
}),
[columnWidth]
);
const tableInstance= useTable(
{
columns: columnsTable,
data: dataTable,
defaultColumn: defaultColumn,
},
useGlobalFilter,
useSortBy,
usePagination,
useBlockLayout
);
当我安装登录DefaultColumn时,它为我提供了正确的计算宽度,但是表单元格总是显示150px。为什么表不显示DefaultColumn宽度值?我该如何正确执行此操作?
I am trying to set columns width dynamically so the sum of the columns width occupy the entire width of the table. I have a react-table component with dynamic width (takes 100% of its parent width), I divide the width by columns.length and set the following:
const defaultColumn = useMemo(
() => ({
width: columnWidth > 0 ? columnWidth : 150,
}),
[columnWidth]
);
const tableInstance= useTable(
{
columns: columnsTable,
data: dataTable,
defaultColumn: defaultColumn,
},
useGlobalFilter,
useSortBy,
usePagination,
useBlockLayout
);
when I console log the defaultColumn it gives me the correct calculated width, but the table cells always show 150px. why the table is not showing the defaultColumn width value? and how can I do this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如我所见,
DefaultColumn
的更改不会触发您的列
定义的重建。因此,要修复它,我建议将您的列定义取决于
DefaultColumn
值。As I see, changes in the
defaultColumn
doesn't trigger rebuilding of yourcolumns
definition.So, to fix it, I propose making your columns definition dependent on
defaultColumn
value.