PrimeReact: how to obtain row index inside column body?

Viewed 845

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?

1 Answers

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>
Related