Page 1 of 1

DataTable -> Column -> expander

Posted: 10 Jan 2018, 17:33
by aokieh
hi,

i use primereact 1.4.0

the expander should not be visible in all rows.
the expander should only shown, if the value in the model is true.

Code: Select all

        let data = [
            {"rowvalue": true, ...},
            {"rowvalue": false, ...}];
            
            <DataTable value={this.props.data}
                       onRowToggle={(e) => this.setState({expandedRows:e.data})}
                       rowExpansionTemplate={(e) => this.rowExpansionTemplate(e)}
                       expandedRows={this.state.expandedRows}>
                <Column expander={rowvalue} style={{width: '3em'}} />
                <Column field="anyvalue" header="AColumn" />
            </DataTable>
can anybody help my?

thanks,
aokieh

Re: DataTable -> Column -> expander

Posted: 26 Feb 2018, 10:56
by merve7
You can use map(https://reactjs.org/docs/lists-and-keys.html) function to access rowvalue or use if statement for example

Code: Select all

<Column expander={your_case?true:false} style={{width: '3em'}} />

Re: DataTable -> Column -> expander

Posted: 28 Mar 2018, 19:20
by domehead100
I have no idea what you mean. If I'm doing

Code: Select all

<Column expander={this.isExpandable} />
and I have a class method

Code: Select all

isExpandable = (rowData, column) => {
   // return boolean based on rowData
  }
the callback never gets called. Are you suggesting we render something into the column that we can then pull off of the DOM element via a ref to look up the row (e.g., like one would do in jQuery)? We can't do that because an expander does not allow custom rendering.

I'm not seeing how map applies here since I'm just specifying a column definition, not a collection of rows.