Reputation: 7923
I have a primereact DataTable
with a column that contains a button like this:
<Column header="Actions" body={
<div>
<Button icon="pi pi-pencil" className="p-button-rounded p-button-text"
onClick={(e) => {
//How do I obtain the row index here?
}
}/>
</div>
}>
</Column>
As you can see from the comment, I need to obtain the row index when the user clicks the button, because I want to perform an action on that specific row.
Is it possible? How do I do it?
Upvotes: 3
Views: 4569
Reputation: 29
Other solution could be:
<Column className="bodyTemplate" body={(featureFlag: FeatureFlag) => RolesBodyTemplate(featureFlag?.roles)} />
Or
<Column className="bodyTemplate" body={userTypesBodyTemplate} />
Upvotes: -1
Reputation: 7923
Ok, after tinkering further I found the solution:
<Column header="Actions" body={(data, props) =>
<div>
<Button icon="pi pi-pencil" className="p-button-rounded p-button-text"
onClick={(e) => {
console.log("row idx: " + props.rowIndex);
}
}/>
</div>
}>
</Column>
Upvotes: 4