【问题标题】:Is it possible to make the new row that is generated by onRowAdd material table to appear at the top of the section?是否可以使 onRowAdd 材料表生成的新行出现在该部分的顶部?
【发布时间】:2021-05-16 10:59:28
【问题描述】:

标题。

如材料表文档中所示,当您使用可编辑的 onRowAdd 时,新行始终在该部分的底部生成。有没有办法使该行出现在顶部?或者如何分配 onClick 效果,以便当用户单击“添加”按钮时,它会自动转到页面底部?让我们使用文档中的示例:https://material-table.com/#/docs/features/editable

【问题讨论】:

  • 我不知道这个库,但你不能用setData([newData, ...data])代替setData([...data, newData])吗?

标签: javascript reactjs react-redux material-ui material-table


【解决方案1】:

有一个名为 addRowPoistion 的 option 可以完全满足您的需求:

在您的表定义中,只需将值设置为"first"。


  <MaterialTable
        columns={tableColumns}
        data={data}
        title="Material Table - Add Row Position "
        options={{
          addRowPosition: "first",
          search: false,
          actionsColumnIndex: -1,
        }}
    ...
    />

这是一个sandbox 的工作示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2020-07-14
    • 2018-05-06
    • 2010-09-26
    • 2023-02-03
    • 2020-11-08
    相关资源
    最近更新 更多