table icon indicating copy to clipboard operation
table copied to clipboard

Access Parent Row value from a subcomponent.

Open robinprashanth opened this issue 9 years ago • 8 comments

Problem Description

I have 2 subcomponents in a react table and when i drill down to second subcomponent from a parents row . I want to access active top parent row values from the present active subcomponent row |-- (parent Row) |-- (1st subcomponent) |-- (2nd subcomponent ,From here I want parent row values)

Steps to Reproduce

|-- (parent Row) |-- (1st subcomponent) |-- (2nd subcomponent ,From here I want parent row values)

robinprashanth avatar Jun 16 '17 05:06 robinprashanth

Can you post your code? This should be easily possible by referencing the props given to the subComponent

tannerlinsley avatar Jun 29 '17 22:06 tannerlinsley

Closing for triage. If you would like to continue investigating this issue, please reopen or join the slack channel for further discussion.

tannerlinsley avatar Aug 02 '17 14:08 tannerlinsley

Is there a solution on tis issue, I have the exact same requirement when i try to access row it has data for all the rows that were expanded not able to figure out which row subcomponent currently i am on.

bhaveshbhatkar avatar Jan 30 '18 21:01 bhaveshbhatkar

It was never confirmed as an "issue". The SubComponent is passed the rowInfo of the parent row. This is a rich object that contains both the original row as well as the row data that was rendered - along with other metadata about the row as it exists inside ReactTable. The simplest way to verify this is to create a dummy SubComponent (it is a React component) and console.log the props that are passed or simply add this prop to your ReactTable instance: SubComponent={(row) => { console.log("row",row); return null; }}

NOTE: I am not where I can test this or easily check the doco - but that or something similar would provide insight into what is passed in the props.

gary-menzel avatar Jan 31 '18 03:01 gary-menzel

it may need to be SubComponent={({ row }) => ..... }.

gary-menzel avatar Jan 31 '18 03:01 gary-menzel

I am using this in multiple places in my code and am rendering a tabbed component with other embedded components and it all works perfectly fine.

gary-menzel avatar Jan 31 '18 03:01 gary-menzel

In regard to aforementioned "rich object" from @gary-menzel , I just got a problem while combining SubComponent with renderEditable.

<ReactTable
  data={data}
  columns={
    [
      {
        Header: "Type",
        accessor: "type",
        Cell: this.renderEditable
      }
    ]
  }
  SubComponent={row => { ... }}

As we know, the part Cell: this.renderEditable would 'automatically' pass only cellInfo. Would anyone mind telling me how to pass additional parameter on Cell: this.renderEditable while keep passing the cellInfo ? Thanks.

juanwisana avatar Jul 04 '18 09:07 juanwisana

I have the same problem. My sub component is another react table.

I need to know the row number of the parent, but I get the row number of the inner table.

I am trying to generate a new prop that will deliver the row.index value of the parent But I fail. Any help is appreciated.

<ReactTable
          data={this.props.data}
          columns = {this.WP2columns}
          pageSize={this.props.data.length+1}
          showPagination={false}
          className="-striped -highlight"
          SubComponent={row => {
            return (
              <div style={{ padding: "0 20px" }}>
                {console.log("WP2 SUBTABLE row=", row) }
                <ReactTable
                  data = {row.original.familywp_goal_tasklist}
                  columns={this.subcolumns}
                  parentRow = {row.index}
                  defaultPageSize={3}
                  showPagination={false}
                />
              </div>
            )
          }}
        />

Mulli avatar Mar 19 '19 18:03 Mulli