最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReactJS: Make a table editable using react-table - Stack Overflow

programmeradmin1浏览0评论

I'm using react-table npm package () for generating my table:

<ReactTable
    data={ tableData }
    columns={ tableColumns }
    showPagination={ false }
    defaultPageSize={ tableData.length }
/>

The table is shown as expected. But now I would like to make this table editable. So I need to use input fields with data value instead of just text data values.

How do I have to do that? I do not understand the docs for this point... So I need some help.

I'm using react-table npm package (https://www.npmjs./package/react-table) for generating my table:

<ReactTable
    data={ tableData }
    columns={ tableColumns }
    showPagination={ false }
    defaultPageSize={ tableData.length }
/>

The table is shown as expected. But now I would like to make this table editable. So I need to use input fields with data value instead of just text data values.

How do I have to do that? I do not understand the docs for this point... So I need some help.

Share Improve this question asked Jul 6, 2017 at 11:49 user3142695user3142695 17.4k55 gold badges194 silver badges375 bronze badges 1
  • 1 If I understand it, <ReactTable> is available in v6 but not v7, which is "headless" – Eric Commented Sep 23, 2020 at 5:39
Add a ment  | 

2 Answers 2

Reset to default 3

First you need to edit the Columns props

Check render: props => <input value={props.row.name} onChange={onChangeFct} />

For example:

const onChangeFct = () => console.log("onChange usually handled by redux");
const tableColumns = [
{
    header: 'Id',
    accessor: 'id'
},
{
    header: 'Name',
    accessor: 'name',
    render: props => <input value={props.row.name} onChange={onChangeFct} />
}
]


<ReactTable
    data={ tableData }
    columns={ tableColumns }
    showPagination={ false }
    defaultPageSize={ tableData.length }
/>

You can use text in place edit plugins like react-x-editable plugin to make table editable as it provides both modes: inline and popup.

发布评论

评论列表(0)

  1. 暂无评论