Search code examples
angularag-gridag-grid-angular

ag-grid default behavior for an angular application


is there any way to set the default properties/attributes for all <ag-grid-angular> in an angular application?

most of this example (first group) are same on all instacne in my application, and the properties/atttributes required in both sides (template.html/ component.ts)

I am search for a configuration change the default of all instances.

      <ag-grid-angular
        style="width: 100%; height: 100%"
        class="ag-theme-alpine"
        [modules]="modules"
        [animateRows]="true"
        [defaultColDef]="defaultColDef"
        [localeText]="localeText"
        [gridOptions]="gridOptions"
        [statusBar]="statusBar"
        [rowModelType]="rowModelType"


        (gridReady)="onGridReady($event)"
        [columnDefs]="columnDefs"
       ></ag-grid-angular>

Solution

  • You can use Grid Options interface for that. With this, you can create some default options and then just add needed properties per usage. For example:

    <ag-grid-angular [gridOptions]="gridOptions">
    <ag-grid-angular>
    
    const DEFAULT_GRID_OPTIONS: GridOptions = {
      animatedRows: true
    }
    
    ...
    class Component {
      public gridOptions: GridOptions = {...DEFAULT_GRID_OPTIONS, rowData: myData};
    }
    

    You can learn more in the docs.