【问题标题】:How to get the all resizable columns width from PrimeReact Datatable如何从 PrimeReact Datatable 获取所有可调整大小的列宽
【发布时间】:2023-01-05 00:15:46
【问题描述】:

我在我的反应项目中使用 primereact 版本“^8.0.0”。并在功能组件中使用 DataTable。

这是我的数据表结构

 <div className="card">
      <DataTable
    size="small"
    value={products}
    selectionMode="multiple" selection={selectedProducts} onSelectionChange={e => setSelectedProducts(e.value)} dataKey="id"
    scrollable scrollHeight="600px" scrollDirection="both" className="mt-3"
    paginator paginatorTemplate="CurrentPageReport FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"
    currentPageReportTemplate="Showing {first} to {last} of {totalRecords}" rows={10} rowsPerPageOptions={[10, 20, 50]}
    resizableColumns columnResizeMode="expand" showGridlines

  >
    <Column field="id" header="Id" style={{ flexGrow: 1, flexBasis: '100px', position: "sticky" }} sortable frozen ></Column>
    <Column field="name" header="Name" style={{ flexGrow: 1, flexBasis: '200px', position: "sticky" }} sortable frozen></Column>
    <Column field="country.name" header="Country" style={{ flexGrow: 1, flexBasis: '200px' }} sortable></Column>
    <Column field="date" header="Date" style={{ flexGrow: 1, flexBasis: '200px' }} sortable></Column>
    <Column field="company" header="Company" style={{ flexGrow: 1, flexBasis: '400px' }} sortable></Column>
    <Column field="status" header="Status" style={{ flexGrow: 1, flexBasis: '200px' }} sortable></Column>
    <Column field="activity" header="Activity" style={{ flexGrow: 1, flexBasis: '200px' }} sortable></Column>
    <Column field="representative.name" header="Representative" style={{ flexGrow: 1, flexBasis: '200px' }} sortable></Column>
    <Column field="balance" header="Balance" style={{ flexGrow: 1, flexBasis: '120px' }} sortable></Column>
  </DataTable>
</div>

【问题讨论】:

  • 你能详细说明你的问题吗?你想完成或计算什么?
  • 调整列大小后,我想将所有列宽存储到数据库中。所以下次我会得到列的预期宽度。
  • 我认为您将不得不编写查询 DOM 的代码,询问每个 DIV 的宽度

标签: reactjs react-functional-component primereact


【解决方案1】:

您可以尝试设置属性(columnResizeMode、resizableColumns)。例如:

<DataTable
size="small" 
value={products} 
columnResizeMode="expand"
resizableColumns={true}>

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    相关资源
    最近更新 更多