Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React antd table expandedRowRender

I'm in need of some help.

I have a datasource on my antd table in my React.Component. On that table i've set the attribute expandedRowRender:

  <Table
    bordered
    size="small"
    columns={columns}
    rowKey={record => record.id}
    expandedRowRender={record => (
      <ProductDetailView
        record={record}
        onChange={this.OnCoverageProductNumberChanged()}
      />
    )}
    dataSource={products}
    pagination={this.state.pagination}
    loading={this.props.isProductsLoading}
    onChange={this.handleChange}
  />

which is currently sending a record to ProductDetailView which is a react.component. I would like to know how I can send the row index to the onChange event as well, so I can track on which row I am looking at.

I hope this is enough information, basically I just need to know how to send the row index to my onChange event.

Thank you in advance.

like image 983
Max Mazur Avatar asked Oct 29 '25 20:10

Max Mazur


1 Answers

The second variable of

expandedRowRender={(record, i) => <p>{i}</p>}

is the row index

you can pass it like this

expandedRowRender={(record, i) => 
    <ProductDetailView 
        record={record} 
        onChange={() => this.OnCoverageProductNumberChanged(i)}
    />
}
like image 145
Stanley Cheung Avatar answered Oct 31 '25 09:10

Stanley Cheung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!