Search code examples
reactjsantd

Using Inputs in Ant design Table


In my application i using Ant design Table my code is like below :

<Table size="small" dataSource={this.props.actionArray}>
            <Column title="Name" dataIndex="id" key="name"/>
            <Column title="Action" key="action"
            render={(text,record)=>(
                <span>
                    <a href="" >Edit</a>
                    <span className="ant-divider"/>
                    <a href="" >Delete</a>
                </span>
            )}
            />

        </Table>

i want when user click on Edit the entire row of table render as a <Input type="text"/> instead of normal text , so users can edit the row data, also a custom save button when user click on it call a function(ex save() ) but i don't know how to this .


Solution

  • Try something like this. Save the editting record id in the state and according to that show or hide the input:

    columns = [
      {
        title: 'Name',
        render: (text, record) =>
          record.id === this.state.editingId ? (
            <Input type="text"/>
          ) : (
            text
          ),
      },
      {
        title: "Action",
        render: (text, record) => (
          <span>
            <a href="" >Edit</a>
            <span className="ant-divider"/>
            <a href="" >Delete</a>
          </span>
        )}
      }
    ]