How to get the data of selected row in ag grid in angular2?

后端 未结 6 1907
温柔的废话
温柔的废话 2021-02-14 05:09

I have setup ag-grid in angular2 which works fine but i am not able to get the value of selected row...There are no errors in my console window...This is how i am initialising t

6条回答
  •  逝去的感伤
    2021-02-14 05:26

    On your HTML bind rowClicked event to your own function as follows.

     
        
    

    then on your TS or in your JS use the api as follows

    onRowClick(event) {
        if (this.selectionMode === 'multiple') {
          this.selectedEntity = this.grid.api.getSelectedRows();
        } else {
          this.selectedEntity = this.grid.api.getSelectedRows()[0];
        }
    }
    

    When your grid has a feature like multiple selections all the selected data won't pass with the event parameter. It will always be the selected row only.

    Reason I didn't encourage the selectionChanged event was, It will always call the rowClicked event before selectionChanged event.

提交回复
热议问题