2

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?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Master_T
  • 7,232
  • 11
  • 72
  • 144

2 Answers2

3

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>
Master_T
  • 7,232
  • 11
  • 72
  • 144
-1

Other solution could be:

<Column className="bodyTemplate" body={(featureFlag: FeatureFlag) => RolesBodyTemplate(featureFlag?.roles)} />

Or

<Column className="bodyTemplate" body={userTypesBodyTemplate} />