Reputation: 741
I have been using datatables.net for my react project. I created two action buttons on every row (edit, remove). Now whenever this listener run then "this" does not work. If I made jquery function to arrow function then "this.props..." works but then data is undefined.
$('#data-table-zero').on('click', '.edit-button', function() {
const data = $('#data-table-zero').DataTable().row($(this).parents('tr')).data();
this.props.history.push({
pathname: `/add-product`,
state: {
selectedRecord: { ...data }
}
});
});
Upvotes: 0
Views: 74
Reputation: 1502
I hope this will help you,
let that = this
$('#data-table-zero').on('click', '.edit-button', function() {
const data = $('#data-table-zero').DataTable().row($(this).parents('tr')).data();
that.props.history.push({
pathname: `/add-product`,
state: {
selectedRecord: { ...data }
}
});
});
Upvotes: 2