# Angular Data Grid Sorting Groups

By default, groups are sorted in ascending order. The [Angular Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid) allows you to modify the default sort order or implement your custom sorting logic.

To configure the group order, set the [`dir`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/groupdescriptor#dir) property of the `GroupDescriptor` to either ascending or descending order.

```ts
public group: GroupDescriptor[]= [{field: 'amount', dir: 'desc'}];
```

To sort groups by another field or implement custom sorting logic, refer to the [custom group sorting](https://www.telerik.com/kendo-angular-ui-develop/components/grid/grouping/group-sorting#custom-group-sorting) section.

The following example demonstrates how to sort groups in descending order.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/grouping/sorting/source.txt)

## Custom Group Sorting

To sort groups based on a specific order, set the [`compare`](https://www.telerik.com/kendo-angular-ui-develop/components/data-query/api/groupdescriptor#compare) property of the `GroupDescriptor` to a custom callback. For examples of using the `compare` callback with regular column sorting, refer to the [Custom Sorting](https://www.telerik.com/kendo-angular-ui-develop/components/grid/sorting/manual-sorting#custom-sorting) section.

```ts
public group: GroupDescriptor[] = [
    {
        field: 'amount',
        compare: (a, b) =>  b.amount - a.amount,
    },
];
```

The returned value must be a number that indicates the relative order of the two elements:

* Negative if `a` < `b`.
* Positive if `a` > `b`.
* Zero if they are equal. NaN is treated as 0.

The following example demonstrates how to sort groups by the **amount** field while the data is grouped by the **transactionId** field.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/grouping/sorting/compare/source.txt)

## Suggested Links

* [Custom Sorting with Compare Callback](https://www.telerik.com/kendo-angular-ui-develop/components/grid/sorting/manual-sorting#custom-sorting)
* [Group Templates](https://www.telerik.com/kendo-angular-ui-develop/components/grid/grouping/manual-grouping)
* [Overview of Data Query](https://www.telerik.com/kendo-angular-ui-develop/components/data-query)
* [API Reference of the GridComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent)
* [API Index of the Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api)
