【问题标题】:PrimeReact: how to obtain row index inside column body?PrimeReact:如何获取列体内的行索引?
【发布时间】:2022-01-15 07:25:41
【问题描述】:

我有一个 primereact DataTable,其中有一列包含这样的按钮:

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

从评论中可以看出,我需要在用户单击按钮时获取行索引,因为我想对该特定行执行操作。

有可能吗?我该怎么做?

【问题讨论】:

    标签: reactjs jsx primereact


    【解决方案1】:

    好的,经过进一步的修改,我找到了解决方案:

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

    【讨论】:

      猜你喜欢
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      相关资源
      最近更新 更多