Romain Linsolas
Romain Linsolas

Reputation: 81627

How to set global properties for ag-Grid?

Let's say I need to set height for my ag-grid. I have to set it on the columns configuration, like that (in an Angular controller):

this.myAgGridOptions = {
  columnDefs: ...,
  rowData: ...,
  headerHeight: 42,
  rowHeight: 42
}

Now, if I have 10 different agGrid in my whole application, is there a way to set these properties only once for all of them, and not for each agGrid declaration?

My question is for the Angular 1 version of AgGrid, but if the solution can be used for any version of AgGrid, it will be great.

Thanks

Upvotes: 1

Views: 1240

Answers (1)

Jarod Moser
Jarod Moser

Reputation: 7338

What will probably work best is to use the extend method that angular provides

So you could have something like this:

this.GlobalAgGridOptions = {
  headerHeight: 42,
  rowHeight: 42
}

this.myAgGridOptionsOne = {
    rowData: rowDataOne,
    columnDefs: columnDefsOne
}

this.myAgGridOptionsTwo = {
    rowData: rowDataTwo,
    columnDefs: columnDefsTwo
}

angular.extends(this.mygridOptionsOne, this.GlobalOptions);
angular.extends(this.mygridOptionsTwo, this.GlobalOptions);

Now both the grid options should have the global options. I guess I am supposing that you are going to be creating somewhat different gridOptions for each grid that you plan on creating. I hope I am supposing correctly

Upvotes: 0

Related Questions