Search code examples
angularscrollbarag-gridag-grid-angular

No scroll bars show up after loading data to grid


I'm having trouble implementing ag-grid in my angular app. I can load data to the grid, but when I load my dataset, there are no scroll bars.

Keyboard navigation to the right to expose more columns shows blank data, telling me that ag-grid hasn't figured out that I'm scrolling.

I've followed all the tutorials provided by ag-grid, as well as tried encapsulating it in a <div>. I can change the size of the grid, but I cannot scroll.

component.css - (there are no global styles applied)
@import "~ag-grid/dist/styles/ag-grid.css";
@import "~ag-grid/dist/styles/ag-theme-balham.css";


component.html - 

<div style="height: 500px; width: 100%">
  <ag-grid-angular
    #agGrid
    style="height: 100%; width: 100%"
    class="ag-theme-balham"
    [rowData]="rowData"
    [columnDefs]="columnDefs"
    (gridReady)='onGridReady($event)'>
  </ag-grid-angular>
</div>


component.ts - 

import {Component, OnInit, ViewChild, ViewEncapsulation} from '@angular/core';
import {GridApi, GridOptions} from 'ag-grid';
import {MyService} from '../../../services/backend-calls/my-service.service';

@Component({
  selector: 'app-my-grid',
  templateUrl: './my-grid.component.html',
  styleUrls: ['./my-grid.component.css'],
  encapsulation: ViewEncapsulation.None
})

export class MyComponent implements OnInit {
  public gridOptions: GridOptions;

  @ViewChild('agGrid') agGrid;

  title = 'app';

  columnDefs = [
    { headerName: 'Column1', field: 'col1' },
    { headerName: 'Column2', field: 'col2' }
  ];

  rowData = [];

  constructor(
    private myService: MyService
  ) {
    this.gridOptions = <GridOptions>{
      context: this,
      rowData: this.rowData,
      columnDefs: this.columnDefs,
    };
  }

  onGridReady(params) {
    this.gridOptions.api = params.api;
    this.gridOptions.columnApi = params.columnApi;
  }

  ngOnInit() {
    this.refreshGridData();
  }

  private refreshGridData() {
    // Propriatary code. Calls MyService to get row data, and updates
    // this.rowData
  }
}

As you can see from the below screenshot, there are no scroll bars. I have at least 500 rows of data, but no way to scroll. Sorry for the blackout. Anyone have any clue what's going on here?

no scroll


Solution

  • So I think I was doing everything correctly, because the solution I found was to roll back my version from ^20.0.0 to ^18.1.2. After running "npm update" everything seemed to work just fine with no code changes.