【问题标题】:using AgGridReact I want to make specific rows selected when grid is binding using ag-grid reactjs使用 AgGridReact 我想在使用 ag-grid reactjs 绑定网格时选择特定行
【发布时间】:2020-09-30 21:13:21
【问题描述】:
 <AgGridReact
                // properties
                columnDefs={this.columnDefs}
                rowData={this.state.rowData}
                defaultColDef={this.defaultColDef}
                // events
              //  isRowSelectable={this.isRowSelectable}
                rowSelection={this.rowSelection}
                onSelectionChanged={this.onSelectionChanged.bind(this)}
                frameworkComponents={this.frameworkComponents}
                onGridReady={this.onGridReady}
              ></AgGridReact>
    onGridReady = (params) => {

        this.gridApi = params.api;
        this.gridColumnApi = params.columnApi;
        params.api.sizeColumnsToFit();

      };

我知道这对我有用 rowNode.setSelected(rowNode.data.id === 58); 但我应该用哪种方法调用它。 在此先感谢:)

【问题讨论】:

    标签: reactjs ag-grid ag-grid-react


    【解决方案1】:

    在这里,一旦数据设置为状态,您就可以设置默认选择的行

    代码 sn-p:

    this.setState({ rowData: data },() => {
        this.gridApi.forEachNodeAfterFilter(function(rowNode) {
            rowNode.setSelected(rowNode.data.id === 58);
        });
    });
    

    WORKING DEMO

    【讨论】:

    • 但是我在componentWillReceiveProps方法populateBeneficiary = async (clientId) =&gt; { //if (!beneficiaryTable) { //alert(this.props.clientId); try { //rowData = { id: 1, firstName: "Bilal", lastName: "Khan", address: "PIB" }; //rowData.push(data); const { data: rowData } = await beneService.getBeneficiaries(clientId); this.setState({ rowData }); } catch (error) { this.setState({ rowData: [] }); console.log(error); } };更新状态@
    • 没问题,你可以this.gridApi....里面设置状态的回调函数如上图。
    • 好的先生它正在选择,但现在我无法更改选择
    • @BilalMásInteligente,您能否创建一个演示,以便我可以帮助您,因为它在我的演示中运行良好。
    • 谢谢先生,问题是当我单击行时,道具会更新并使 componentWillReceiveProps() 再次渲染,现在我对其应用条件。 :)
    猜你喜欢
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2020-09-08
    • 2020-03-29
    • 2020-06-08
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多