2017-04-04 3 views
1

Ich verwende die kostenlose Version von ag-Grid in meiner Angular 4 Application.Angular4 ag-Grid: API von GridOptions ist nicht definiert

Im folgenden Code ich das Netz automatisch in den Konstruktor, um die Größe wollen:

constructor(private modalService: NgbModal) { 
    this.gridOptions = <GridOptions>{}; 

    const columnDefs = [...]; 
    const rowData = [...]; 

    this.gridOptions.columnDefs = columnDefs; 
    this.gridOptions.rowData = rowData; 

    this.gridOptions.api.sizeColumnsToFit(); 
} 

Aber in den Entwickler-Tools I die folgende Fehlermeldung erhalten:

ERROR TypeError: Cannot read property 'sizeColumnsToFit' of undefined 
+0

Hatten die Antwort von @Jarod Moser Ihre Frage beantworten ? Ich kann mein Raster auch nicht in angle4 arbeiten lassen. Wenn Ihr Code funktioniert, können Sie ihn bitte posten, damit ich auch Hilfe bekommen kann. Dank –

Antwort

0

Die gridOptions.api ist nur verfügbar, nachdem Sie eine neue agGrid.Grid-Instanz erstellt haben. Zum Beispiel:

this.gridOptions = <GridOptions>{}; 
//just an empty object right now 

const columnDefs = [...]; 
const rowData = [...]; 

this.gridOptions.columnDefs = columnDefs; 
this.gridOptions.rowData = rowData; 
// all the gridOptions has right now is columnDefs and rowData attributes 

this.gridOptions.api.sizeColumnsToFit(); 

//wherever you create the grid instance... 
new agGrid.Grid(gridDiv, gridOptions) 
//now the gridOptions object that you created has been filled out 
//  with the api and columnApi attributes and functions 
+0

Wie verwende ich die GridDiv in neuen agGrid.Grid (GridDiv, GridOptions). Ist es eine Vorlagenvariable? –

0

Haken der api-Funktionen zum Api Objekt auf dem onGridReady Ereignisse, weicht man im Konstruktor festlegen muß ...

constructor() { 
    this.gridOptions = <GridOptions>{ 
     onGridReady:() => { 
     this.gridOptions.api.addEventListener('rowClicked', this.myRowClickedHandler); 
     } 
    }; 

myRowClickedHandler(event) { 
    this.createdDate = event.data.createdDate; 
} 
Verwandte Themen