Search code examples
angularag-gridag-grid-angular

how do enable sorting in an angular ag grid


Im trying to add sorting to a simple ag grid but i keep getting an error saying : Can't bind to 'enableSorting' since it isn't a known property of 'ag-grid-angular'.

Here is the template:

<ag-grid-angular
 [enableSorting]="true"
 [rowData]="rowData"
 [columnDefs]="columnDefs"
>
</ag-grid-angular>

i even tried using a GridOptions object but it wont recognize enableSorting or enableFilter but it does recognize pagination. what am i doing wrong?

I'm following this introductory guide on ag grid's blog. without the sorting part the grid works as expected so i dont think its something related to configuration(imported module and import array) but i double checked anyway and its all setup correctly! angular version 10 ag grid version 24.


Solution

  • I personally would recommend using GridOptions again - as it's likely you'll want to specify how many other parts of Ag-Grid look and feel.

    If you'd like sorting to be available on all of the columns in your grid, simply use the following:

    gridOptions: GridOptions = {
      defaultColDef: {
        sortable: true
      }
    }
    

    And then provide grid options to your Ag-Grid in the html:

    <ag-grid-angular
     [gridOptions]="gridOptions"
     [rowData]="rowData"
     [columnDefs]="columnDefs"
    >
    </ag-grid-angular>