Facing issue with DataTable template column

UI Components for React
Post Reply
Rithuu
Posts: 1
Joined: 30 Apr 2018, 07:00

30 Apr 2018, 07:13

Hi Team,

I've two buttons in Templated ActionColumn. The onClick event of these buttons is unable to access any function or props/state of parent component.

actionTemplate(rowData, column) {
return (<div>
<Button type="button" icon="fa-save" className="ui-button-success"></Button>
<Button type="button" icon="fa-times" className="ui-button-danger" onClick={(e) => console.log(this.props)} />
</div>);
}

<Column body={this.actionTemplate} style={{textAlign:'center', width: '6em'}}/>

this.props is evaluating as undfined.
===================================================================================================
handleDelete(e) {
e.preventDefault();
console.log(this.state.selectedItem);
}

actionTemplate(rowData, column) {
return (<div>
<Button type="button" icon="fa-save" className="ui-button-success"></Button>
<Button type="button" icon="fa-times" className="ui-button-danger" onClick={this.handleDelete} />
</div>);
}

Error in developer console as it could not identify "handleDelete"

Thanks,
Rithuu

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

10 May 2018, 14:13

Hi,

For first issue, you can use column object; <Button type="button" icon="fa-times" className="ui-button-danger" onClick={(e) => console.log(column)} />

For second issue, you need to bind your method. Please try; <Button type="button" icon="fa-times" className="ui-button-danger" onClick={this.handleDelete.bind(this)} />

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests