行的Ag-Grid DOM

时间:2019-02-28 12:10:17

标签: angular ag-grid ag-grid-angular

如何在ag-grid中获取该行的DOM元素?

 this.gridOptions.api.getRowNode(id)

这样可以获取一行对象。但是如何获取此行的DOM?

1 个答案:

答案 0 :(得分:0)

正确的解决方案:

constructor(public myElement: ElementRef) { }

this.gridOptions = <GridOptions> {
  ...
};

ngAfterViewInit() { 
    const countOfRows = this.gridOptions.api.getDisplayedRowCount(); 
    for (let i = 0; i < countOfRows; i++) {
      const elements = this.myElement.nativeElement.querySelectorAll(`[row-index="${i}"]`);
      const row = elements[1];
      row.addEventListener('dragover', function() {
        row.style.backgroundColor = 'yellow';
      });
    }
}