I'm using React + Ant.design and I need to make a table where each row will be a form with a number of inputs which are represents fields of this row and user can edit value in each field and push Save at the end of each row.
But I have no idea how to do it, because there is only datasource property in Table ponent for the plain data in JSON format.
const dataSource = [
{
id: 1,
name: 'Name 1',
number: 1,
username: 'user1',
date: '09-09-2011',
status: 'reviewed'
},
{
id: 2,
name: 'Name 2',
number: 2,
username: 'user2',
date: '01-10-2021',
status: 'reviewed'
}
]
<Table
size="small"
rowKey="id"
dataSource={dataSource} <-- row data here, need to have form with input for each field
columns={this.columns}
bordered={false}
rowClassName={(record, index) => {
return cssClasses.tableRow
}}
title={TableTitle}
>
Is it possible at all to have forms within table rows or it's better to make it using just React ponents?
I'm using React + Ant.design and I need to make a table where each row will be a form with a number of inputs which are represents fields of this row and user can edit value in each field and push Save at the end of each row.
But I have no idea how to do it, because there is only datasource property in Table ponent for the plain data in JSON format.
const dataSource = [
{
id: 1,
name: 'Name 1',
number: 1,
username: 'user1',
date: '09-09-2011',
status: 'reviewed'
},
{
id: 2,
name: 'Name 2',
number: 2,
username: 'user2',
date: '01-10-2021',
status: 'reviewed'
}
]
<Table
size="small"
rowKey="id"
dataSource={dataSource} <-- row data here, need to have form with input for each field
columns={this.columns}
bordered={false}
rowClassName={(record, index) => {
return cssClasses.tableRow
}}
title={TableTitle}
>
Is it possible at all to have forms within table rows or it's better to make it using just React ponents?
Share Improve this question edited Feb 20, 2018 at 9:31 Dmitry asked Feb 20, 2018 at 9:22 DmitryDmitry 8673 gold badges16 silver badges31 bronze badges2 Answers
Reset to default 0I'm not fully understand your problem
Do you mean the render callback from columns
props?
You can defined in columns props to render an input:
const column = [
{
title: 'input',
dataIndex: 'value',
render: (value, row, index) => { return <input /> } // just an example
}
]
for more info check this example:
https://ant.design/ponents/table/#ponents-table-demo-edit-row
Yes its possible...
your datasource should be in a state
you can do something like this
state = {dataSource: this.dataSource.map(data => {
return {
key: data.id,
item: (
<Select
<Option></Option>
</Select>
),
quantity: <InputNumber/>,
ments:<TextArea/>,
};
})}`
and you can replace this.dataSource
with this.state.dataSource
<Table
dataSource={this.state.dataSource}
/>