# Custom Sorting

Canonical page: https://www.adaptabletools.com/docs/handbook-custom-sorting

- Custom Sorting gives a column a bespoke sorting order (replacing AG Grid's default for the column's data type)
- A Custom Sort can be provided in 2 ways:
  - a **list of values** in Initial Adaptable State (and manageable in the Settings Panel)
  - a **comparer function** in `customSortOptions.customSortComparers`
- Comparers take precedence over list-based sorts for the same column

- This page discusses Custom Sorting - providing a non-default sort for a Column
- For **layout column sorting** (`ColumnSorts`), see [Sorting](https://www.adaptabletools.com/docs/handbook-sorting/index.md)

Custom sorting enables [Adaptable columns](https://www.adaptabletools.com/docs/dev-guide-columns-adaptable-column/index.md) to be given a bespoke sort order.

This will be applied by AdapTable whenever the column is sorted in place of the column's default sort order.

- Custom Sorts are applied when a Column is sorted in AG Grid in both table and pivot Layouts
- A Custom Sort can be limited to specific Layouts via [Layout Extensions](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md)

Custom sorting is useful when the contents of a column are typically ordered in a non-standard way.

### Default Sorting Rules for each Column DataType

The default sort order in AG Grid for each data type is:

| Column Data Type | Rule               |
| ---------------- | ------------------ |
| String           | Alphabetical Order |
| Number           | Highest to Lowest  |
| Date             | Oldest to Newest   |

This is what is used when a Column is sorted in the absence of Custom Sorting

For example, a 'Ratings' column can be sorted by rating (i.e. 'AAA', 'AA1' etc) rather than alphabetically (the default for string columns).

A Custom Sort can be one of 2 types:

| Type                                           | Provided in                                                                                                                            |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| **Hard-coded List** of values | [Custom Sort Initial State](https://www.adaptabletools.com/docs/technical-reference-custom-sorting/index.md) (or via the UI)                             |
| **Comparer** function                          | [Custom Sort Options](https://www.adaptabletools.com/docs/technical-reference-custom-sorting/index.md) — invoked by AdapTable each time column is sorted |

- Only one Custom Sort can be supplied per Column
- Custom Sort Comparers **take precedence** over Hard-coded Lists

## Defining Custom Sorts

At design time developers can configure both types of Custom Sorts.

### Hardcoded Values

Custom Sorts can be provided using a list of values in the [Custom Sort](https://www.adaptabletools.com/docs/technical-reference-custom-sorting/index.md) section of Initial Adaptable State.

AdapTable will sort the Column according to the order of the supplied values.

- It is likely the column will contain values that are not included in the custom sort list
- AdapTable will sort them according to the default alphabetic order

### Defining a Custom Sort with Hardcoded Values

Add a `CustomSort` section containing an array of [`CustomSort`](https://www.adaptabletools.com/docs/reference/customsort.md) objects.

Choose a unique name for the Custom Sort

Specify the Id of Column which will use the Custom Sort

Supply an ordered list by which the column will be sorted

Values not provided are sorted using Column's default sort order

```js [[1, 2, "CustomSort"],[1, 3, "CustomSorts"],[2, 5, "Name"],[3, 6, "ColumnId"], [4, 7, "SortedValues"]]
const initialState: InitialState = {
    CustomSort: {
        CustomSorts: [
        {
          Name: 'CustomSort-Rating',
          ColumnId: 'Rating',
          SortedValues: ['AAA', 'AA+', 'AA', 'AA-'], // etc.
        },
    ],
  },
} as InitialState;
```

**Example: Custom Sorts: Values**

Providing Custom Sort Initial State

- This demo illustrates 2 Columns that contain Custom Sorts which provide a list of Values (and for each we add a Column Sort to the [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md)):
  - `License` - orders using `Other` as first cell value
  - `Language` - orders as 'TypeScript', 'JavaScript', 'HTML'

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Sort Values',
  initialState: {
    Dashboard: {
      ModuleButtons: ['CustomSort'],
    },
    CustomSort: {
      CustomSorts: [
        {
          Name: 'customSort-license',
          ColumnId: 'license',
          SortedValues: ['Other'],
        },
        {
          Name: 'customSort-language',
          ColumnId: 'language',
          SortedValues: ['TypeScript', 'JavaScript'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          ColumnSorts: [
            {
              ColumnId: 'license',
              SortOrder: 'Asc',
            },
            {
              ColumnId: 'language',
              SortOrder: 'Asc',
            },
          ],
          TableColumns: [
            'name',
            'license',
            'language',
            'week_issue_change',
            'github_stars',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'open_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### Comparer Function

For more complicated scenarios a `customSortComparer` function can be supplied by developers.

This comparer function will be invoked by AdapTable each time the Column is sorted.

Comparer functions are provided in the `customSortComparers` property of [Custom Sort Options](https://www.adaptabletools.com/docs/technical-reference-custom-sorting/index.md).

### `customSortComparers`

Custom Sort Column Comparer Functions

  [`ColumnValuesComparer[]`](https://www.adaptabletools.com/docs/reference/columnvaluescomparer.md)

Functions used to compare column values when implementing custom sort.

As there can be only one Sort Order for a Column, implementations provided here **take precedence** over those given as a hardcoded list in Initial Adaptable State

The function returns a `ColumnValuesComparer` object which is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [comparer](https://www.adaptabletools.com/docs/reference/columnvaluescomparer.md#comparer) | [`AdaptableComparerFunction`](https://www.adaptabletools.com/docs/reference/adaptablecomparerfunction.md)`<TData>` | Comparer function to use |
| [name](https://www.adaptabletools.com/docs/reference/columnvaluescomparer.md#name) | `string` | Name of the CustomSort Comparer |
| [scope](https://www.adaptabletools.com/docs/reference/columnvaluescomparer.md#scope) | [`ColumnScope`](https://www.adaptabletools.com/docs/reference/columnscope.md) | Column for which to compare values |

The `scope` property is of type [`ColumnScope`](https://www.adaptabletools.com/docs/reference/columnscope.md) which is [commonly used across AdapTable](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md).

The `comparer` property is of type [`AdaptableComparerFunction`](https://www.adaptabletools.com/docs/reference/adaptablecomparerfunction.md) which is defined as follows:

```ts
/**
 * Standard comparer function used to evaluate custom sorts
 * should return -1, 0, 1 as required
 * valueA and valueB are first and second cell to compare
 * nodeA and nodeB are first and second rows to compare
 */
export type AdaptableComparerFunction = (
  valueA: any,
  valueB: any,
  nodeA: IRowNode,
  nodeB: IRowNode
) => number;
```

The Comparer can be used like this:

```ts {4}
// Compare Issue Change by size of change (by absolute value)
const adaptableOptions: AdaptableOptions = {
  customSortOptions: {
    customSortComparers: [
      {
        name: 'absolute_custom_sort',
        scope: {ColumnIds: ['week_issue_change']},
        comparer: (
          valueA: any,
          valueB: any,
          nodeA?: IRowNode,
          nodeB?: IRowNode
        ) => {
          return Math.abs(valueB) - Math.abs(valueA);
        },
      },
    ],
  },
};
```

- Unlike with Hardcoded Values the `customSortComparer` function can be given [Column Scope](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md)
- This allows, for example, for a single `customSortComparer` function to be provided for all Date columns

### Defining a Custom Sort using a CustomSortComparer function

Just a few steps are required to define a Custom Sort Comparer.

In this example, we provide a Comparer which will ignore negatives and sort by absolute value

Add `customSortComparers` property to Custom Sort Options

Provide a unique name for the Comparer

The commonly-used [Column Scope object](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md) defines where the Custom Sort Comparer will run. It can be:

- One or more ColumnIds
- A [Cell Data Type](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) (e.g. text, date, number)
- A [Column Type](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md)

The function receives 2 cell values (and their containing row nodes)

The evaluation returns -1, 1 or 0 based on comparison being made

```ts [[1, 3, "customSortComparers"],[2, 5, "name"],[3, 6, "scope"],[4, 9, "comparer"]]
// Sort numeric columns by absolute value
customSortOptions: {
  customSortComparers: [
    {
      name: 'absolute_sort',
      scope: {
        DataTypes: ['number'],
      },
      comparer: (valA: any, valB: any) => {
        return Math.abs(valB) - Math.abs(valA);
      },
    },
  ],
};
```

**Example: Custom Sorts: Functions**

Providing Custom Sort Functions

- This demo contains 3 Columns with Custom Sorts provided via a `customSortComparer` Function:
  - `Issue Change` - the `customSortComparer` negates the numbers to order changes by size (we sort on this by default in the [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md))
  - `Name` - the `customSortComparer` orders the column according to the value in the `GitHub Stars` column
  - `Rating` - the `customSortComparer` uses the `localeCompare` function (so it orders a, A, b, B, c, C etc)

- Sort on the `Name` column to see how its sorted according to the `GitHub Stars` column value
- Sort on the `Rating` column to see how the comparer function sorts ignoring case

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {IRowNode} from 'ag-grid-enterprise';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Sort Functions',
  customSortOptions: {
    customSortComparers: [
      {
        name: 'absolute_sort',
        scope: {
          ColumnIds: ['week_issue_change'],
        },
        comparer: (valueA: any, valueB: any) => {
          return Math.abs(valueB) - Math.abs(valueA);
        },
      },
      {
        name: 'rating_sort',
        scope: {
          ColumnIds: ['rating'],
        },
        comparer: (valueA: any, valueB: any) => {
          return valueA.localeCompare(valueB);
        },
      },
      {
        name: 'name_sort',
        scope: {
          ColumnIds: ['name'],
        },
        comparer: (
          valueA: any,
          valueB: any,
          nodeA: IRowNode | undefined,
          nodeB: IRowNode | undefined
        ) => {
          const nodeAGitHubStars = nodeA?.data['github_stars'];
          const nodeBGitHubStars = nodeB?.data['github_stars'];
          if (nodeAGitHubStars > nodeBGitHubStars) {
            return -1;
          }
          if (nodeAGitHubStars < nodeBGitHubStars) {
            return 1;
          }
          return 0;
        },
      },
    ],
  },

  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          ColumnSorts: [
            {
              ColumnId: 'week_issue_change',
              SortOrder: 'Asc',
            },
          ],
          TableColumns: [
            'name',
            'github_stars',
            'rating',
            'week_issue_change',
            'license',
            'language',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'open_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/rowData.ts`**

```ts
export interface WebFramework {
  id: number;
  name: string;
  full_name?: string;
  html_url?: string;
  rating: string;
  created_at: string;
  updated_at: string;
  pushed_at: string;
  homepage?: string;
  github_stars: number;
  language: string;
  forks_count?: number;
  open_issues_count: number;
  license: string;
  topics?: string[];
  github_watchers: number;
  has_projects: boolean;
  has_wiki: boolean;
  has_pages: boolean;
  closed_issues_count: number;
  open_pr_count: number;
  closed_pr_count: number;
  week_issue_change: number;
}

export const rowData: WebFramework[] = [
  {
    id: 10270250,
    name: 'react',
    full_name: 'facebook/react',
    html_url: 'https://github.com/facebook/react',
    rating: 'A',
    created_at: new Date('2013-05-24T16:15:54').toDateString(),
    updated_at: new Date('2021-12-20T09:03:49').toDateString(),
    pushed_at: new Date('2021-12-19T14:34:59').toDateString(),
    homepage: 'https://reactjs.org',
    github_stars: 179429,
    language: 'JavaScript',
    forks_count: 36403,
    open_issues_count: 920,
    license: 'MIT License',
    topics: ['declarative', 'frontend', 'javascript', 'library', 'react', 'ui'],
    github_watchers: 6671,
    has_projects: true,
    has_wiki: true,
    has_pages: true,
    closed_issues_count: 10326,
    open_pr_count: 249,
    closed_pr_count: 11408,
    week_issue_change: 5,
  },
  {
    id: 24195339,
    name: 'angular',
    full_name: 'angular/angular',
    html_url: 'https://github.com/angular/angular',
    rating: 'a',
    created_at: new Date('2014-09-18T16:12:01').toDateString(),
    updated_at: new Date('2021-12-20T08:37:07').toDateString(),
    pushed_at: new Date('2021-12-19T21:54:01').toDateString(),
    homepage: 'https://angular.io',
    github_stars: 78348,
    language: 'TypeScript',
    forks_count: 20569,
    open_issues_count: 1889,
    license: 'MIT License',
    topics: [
      'angular',
      'javascript',
      'pwa',
      'typescript',
      'web',
      'web-framework',
      'web-performance',
    ],
    github_watchers: 3119,
    has_projects: true,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 21706,
    open_pr_count: 159,
    closed_pr_count: 20052,
    week_issue_change: 12,
  },
  {
    id: 11730342,
    name: 'vue',
    full_name: 'vuejs/vue',
    html_url: 'https://github.com/vuejs/vue',
    rating: 'B',
    created_at: new Date('2013-07-29T03:24:51').toDateString(),
    updated_at: new Date('2021-12-20T08:47:06').toDateString(),
    pushed_at: new Date('2021-12-20T08:10:16').toDateString(),
    homepage: 'http://vuejs.org',
    github_stars: 191435,
    language: 'JavaScript',
    forks_count: 30945,
    open_issues_count: 546,
    license: 'MIT License',
    topics: ['framework', 'frontend', 'javascript', 'vue'],
    github_watchers: 6187,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 9318,
    open_pr_count: 224,
    closed_pr_count: 1878,
    week_issue_change: -9,
  },
  {
    id: 74293321,
    name: 'svelte',
    full_name: 'sveltejs/svelte',
    html_url: 'https://github.com/sveltejs/svelte',
    rating: 'C',
    created_at: new Date('2016-11-20T18:13:05').toDateString(),
    updated_at: new Date('2021-12-20T08:56:37').toDateString(),
    pushed_at: new Date('2021-12-19T14:53:30').toDateString(),
    homepage: 'https://svelte.dev',
    github_stars: 53935,
    language: 'TypeScript',
    forks_count: 2584,
    open_issues_count: 604,
    license: 'MIT License',
    topics: ['compiler', 'template', 'ui'],
    github_watchers: 874,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 3549,
    open_pr_count: 104,
    closed_pr_count: 2738,
    week_issue_change: 14,
  },
  {
    id: 224663696,
    name: 'alpine',
    full_name: 'alpinejs/alpine',
    html_url: 'https://github.com/alpinejs/alpine',
    rating: 'A',
    created_at: new Date('2019-11-28T13:51:55').toDateString(),
    updated_at: new Date('2021-12-20T08:12:43').toDateString(),
    pushed_at: new Date('2021-12-14T16:02:26').toDateString(),
    homepage: 'https://alpinejs.dev',
    github_stars: 19338,
    language: 'HTML',
    forks_count: 837,
    open_issues_count: 19,
    license: 'MIT License',
    topics: [],
    github_watchers: 202,
    has_projects: false,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 544,
    open_pr_count: 13,
    closed_pr_count: 546,
    week_issue_change: 21,
  },
  {
    id: 95797174,
    name: 'lit',
    full_name: 'lit/lit',
    html_url: 'https://github.com/lit/lit',
    rating: 'b',
    created_at: new Date('2017-06-29T16:27:16').toDateString(),
    updated_at: new Date('2021-12-20T07:20:35').toDateString(),
    pushed_at: new Date('2021-12-17T03:45:26').toDateString(),
    homepage: 'https://lit.dev',
    github_stars: 9752,
    language: 'JavaScript',
    forks_count: 528,
    open_issues_count: 207,
    license: 'BSD 3-Clause',
    topics: ['html-templates', 'lit', 'lit-element', 'lit-html'],
    github_watchers: 204,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 895,
    open_pr_count: 53,
    closed_pr_count: 1138,
    week_issue_change: -45,
  },
  {
    id: 76694515,
    name: 'stimulus',
    full_name: 'hotwired/stimulus',
    html_url: 'https://github.com/hotwired/stimulus',
    rating: 'b',
    created_at: new Date('2016-12-17T00:19:29').toDateString(),
    updated_at: new Date('2021-12-20T07:20:01').toDateString(),
    pushed_at: new Date('2021-12-17T20:47:34').toDateString(),
    homepage: 'https://stimulus.hotwired.dev/',
    github_stars: 11049,
    language: 'TypeScript',
    forks_count: 316,
    open_issues_count: 17,
    license: 'MIT License',
    topics: [],
    github_watchers: 221,
    has_projects: false,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 282,
    open_pr_count: 5,
    closed_pr_count: 191,
    week_issue_change: -11,
  },
  {
    id: 1801829,
    name: 'ember.js',
    full_name: 'emberjs/ember.js',
    html_url: 'https://github.com/emberjs/ember.js',
    rating: 'c',
    created_at: new Date('2011-05-25T23:39:40').toDateString(),
    updated_at: new Date('2021-12-19T07:57:31').toDateString(),
    pushed_at: new Date('2021-12-20T07:15:54').toDateString(),
    homepage: 'https://emberjs.com',
    github_stars: 22093,
    language: 'JavaScript',
    forks_count: 4253,
    open_issues_count: 427,
    license: 'MIT License',
    topics: ['ember', 'hacktoberfest', 'javascript', 'javascript-framework'],
    github_watchers: 908,
    has_projects: true,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 6187,
    open_pr_count: 94,
    closed_pr_count: 9574,
    week_issue_change: -22,
  },
  {
    id: 82095231,
    name: 'stencil',
    full_name: 'ionic-team/stencil',
    html_url: 'https://github.com/ionic-team/stencil',
    rating: 'C',
    created_at: new Date('2017-02-15T18:57:07').toDateString(),
    updated_at: new Date('2021-12-20T05:46:50').toDateString(),
    pushed_at: new Date('2021-12-16T21:15:17').toDateString(),
    homepage: 'https://stenciljs.com',
    github_stars: 9884,
    language: 'TypeScript',
    forks_count: 641,
    open_issues_count: 499,
    license: 'Other',
    topics: [
      'custom-elements',
      'ionic',
      'progressive-web-app',
      'pwa',
      'ssg',
      'ssr',
      'static-site-generator',
      'stencil',
      'stenciljs',
      'typescript',
      'webcomponents',
    ],
    github_watchers: 203,
    has_projects: true,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 1929,
    open_pr_count: 46,
    closed_pr_count: 743,
    week_issue_change: 12,
  },
  {
    id: 130884470,
    name: 'solid',
    full_name: 'solidjs/solid',
    html_url: 'https://github.com/solidjs/solid',
    rating: 'B',
    created_at: new Date('2018-04-24T16:36:27').toDateString(),
    updated_at: new Date('2021-12-20T08:29:47').toDateString(),
    pushed_at: new Date('2021-12-19T21:06:01').toDateString(),
    homepage: 'https://solidjs.com',
    github_stars: 13119,
    language: 'TypeScript',
    forks_count: 330,
    open_issues_count: 21,
    license: 'MIT License',
    topics: [
      'declarative',
      'fine-grained',
      'javascript',
      'jsx',
      'performance',
      'proxies',
      'reactive',
      'solid',
    ],
    github_watchers: 161,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 366,
    open_pr_count: 3,
    closed_pr_count: 164,
    week_issue_change: 23,
  },
  {
    id: 17814354,
    name: 'mithril.js',
    full_name: 'MithrilJS/mithril.js',
    html_url: 'https://github.com/MithrilJS/mithril.js',
    rating: 'a',
    created_at: new Date('2014-03-17T01:59:39').toDateString(),
    updated_at: new Date('2021-12-20T03:17:55').toDateString(),
    pushed_at: new Date('2021-11-24T10:16:47').toDateString(),
    homepage: 'https://mithril.js.org',
    github_stars: 13064,
    language: 'JavaScript',
    forks_count: 940,
    open_issues_count: 173,
    license: 'MIT License',
    topics: [
      'framework',
      'javascript',
      'mithril',
      'router',
      'vdom',
      'virtual-dom',
      'xhr',
    ],
    github_watchers: 324,
    has_projects: true,
    has_wiki: true,
    has_pages: true,
    closed_issues_count: 1368,
    open_pr_count: 28,
    closed_pr_count: 1144,
    week_issue_change: 57,
  },
  {
    id: 167174,
    name: 'jquery',
    full_name: 'jquery/jquery',
    html_url: 'https://github.com/jquery/jquery',
    rating: 'B',
    created_at: new Date('2009-04-03T15:20:14').toDateString(),
    updated_at: new Date('2021-12-20T06:13:48').toDateString(),
    pushed_at: new Date('2021-12-17T16:50:04').toDateString(),
    homepage: 'https://jquery.com',
    github_stars: 55666,
    language: 'JavaScript',
    forks_count: 20187,
    open_issues_count: 84,
    license: 'MIT License',
    topics: ['jquery'],
    github_watchers: 3306,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 2083,
    open_pr_count: 13,
    closed_pr_count: 2692,
    week_issue_change: 15,
  },
  {
    id: 5532320,
    name: 'polymer',
    full_name: 'Polymer/polymer',
    html_url: 'https://github.com/Polymer/polymer',
    rating: 'a',
    created_at: new Date('2012-08-23T20:56:30').toDateString(),
    updated_at: new Date('2021-12-19T05:05:03').toDateString(),
    pushed_at: new Date('2021-12-07T22:20:44').toDateString(),
    homepage: 'https://polymer-library.polymer-project.org/',
    github_stars: 21724,
    language: 'HTML',
    forks_count: 2026,
    open_issues_count: 281,
    license: 'Other',
    topics: ['polymer', 'web-components'],
    github_watchers: 894,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 3648,
    open_pr_count: 26,
    closed_pr_count: 1404,
    week_issue_change: 9,
  },
  {
    id: 952189,
    name: 'backbone',
    full_name: 'jashkenas/backbone',
    html_url: 'https://github.com/jashkenas/backbone',
    rating: 'C',
    created_at: new Date('2010-09-30T19:41:28').toDateString(),
    updated_at: new Date('2021-12-19T05:50:57').toDateString(),
    pushed_at: new Date('2020-05-19T16:52:55').toDateString(),
    homepage: 'http://backbonejs.org',
    github_stars: 27840,
    language: 'JavaScript',
    forks_count: 5608,
    open_issues_count: 85,
    license: 'MIT License',
    topics: [],
    github_watchers: 1365,
    has_projects: true,
    has_wiki: true,
    has_pages: true,
    closed_issues_count: 2335,
    open_pr_count: 32,
    closed_pr_count: 1797,
    week_issue_change: -14,
  },
  {
    id: 757363,
    name: 'knockout',
    full_name: 'knockout/knockout',
    html_url: 'https://github.com/knockout/knockout',
    rating: 'c',
    created_at: new Date('2010-07-05T08:08:34').toDateString(),
    updated_at: new Date('2021-12-18T17:20:52').toDateString(),
    pushed_at: new Date('2021-10-09T07:42:49').toDateString(),
    homepage: 'http://knockoutjs.com/',
    github_stars: 10122,
    language: 'JavaScript',
    forks_count: 1571,
    open_issues_count: 362,
    license: 'Other',
    topics: ['data-binding', 'javascript', 'knockout', 'mvvm'],
    github_watchers: 549,
    has_projects: true,
    has_wiki: true,
    has_pages: true,
    closed_issues_count: 1534,
    open_pr_count: 72,
    closed_pr_count: 670,
    week_issue_change: 63,
  },
  {
    id: 191051391,
    name: 'redwood',
    full_name: 'redwoodjs/redwood',
    html_url: 'https://github.com/redwoodjs/redwood',
    rating: 'b',
    created_at: new Date('2019-06-09T20:17:57').toDateString(),
    updated_at: new Date('2021-12-20T01:41:55').toDateString(),
    pushed_at: new Date('2021-12-20T00:37:09').toDateString(),
    homepage: 'https://redwoodjs.com',
    github_stars: 10334,
    language: 'TypeScript',
    forks_count: 431,
    open_issues_count: 269,
    license: 'MIT License',
    topics: [
      'apollo',
      'graphql',
      'hacktoberfest',
      'jamstack',
      'prisma',
      'react',
    ],
    github_watchers: 80,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 1071,
    open_pr_count: 35,
    closed_pr_count: 2602,
    week_issue_change: 14,
  },
  {
    id: 36040894,
    name: 'gatsby',
    full_name: 'gatsbyjs/gatsby',
    html_url: 'https://github.com/gatsbyjs/gatsby',
    rating: 'a',
    created_at: new Date('2015-05-21T22:43:05').toDateString(),
    updated_at: new Date('2021-12-20T09:04:22').toDateString(),
    pushed_at: new Date('2021-12-20T08:04:34').toDateString(),
    homepage: 'https://www.gatsbyjs.com',
    github_stars: 51931,
    language: 'JavaScript',
    forks_count: 10049,
    open_issues_count: 359,
    license: 'MIT License',
    topics: [
      'blog',
      'compiler',
      'documentation-tool',
      'gatsby',
      'graphql',
      'react',
      'static-site-generator',
      'web-app',
    ],
    github_watchers: 853,
    has_projects: true,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 12975,
    open_pr_count: 180,
    closed_pr_count: 19058,
    week_issue_change: -34,
  },
  {
    id: 26316966,
    name: 'cyclejs',
    full_name: 'cyclejs/cyclejs',
    html_url: 'https://github.com/cyclejs/cyclejs',
    rating: 'A',
    created_at: new Date('2014-11-07T11:28:45').toDateString(),
    updated_at: new Date('2021-12-20T06:39:49').toDateString(),
    pushed_at: new Date('2021-12-17T11:03:37').toDateString(),
    homepage: 'http://cycle.js.org',
    github_stars: 9999,
    language: 'TypeScript',
    forks_count: 421,
    open_issues_count: 102,
    license: 'MIT License',
    topics: [
      'cyclejs',
      'framework',
      'functional-programming',
      'hacktoberfest',
      'javascript',
      'reactive-programming',
      'rxjs',
      'typescript',
    ],
    github_watchers: 205,
    has_projects: true,
    has_wiki: true,
    has_pages: true,
    closed_issues_count: 563,
    open_pr_count: 26,
    closed_pr_count: 301,
    week_issue_change: -2,
  },
  {
    id: 42283287,
    name: 'preact',
    full_name: 'preactjs/preact',
    html_url: 'https://github.com/preactjs/preact',
    rating: 'B',
    created_at: new Date('2015-09-11T02:40:18').toDateString(),
    updated_at: new Date('2021-12-20T09:02:15').toDateString(),
    pushed_at: new Date('2021-12-17T23:21:58').toDateString(),
    homepage: 'https://preactjs.com',
    github_stars: 30538,
    language: 'JavaScript',
    forks_count: 1702,
    open_issues_count: 222,
    license: 'MIT License',
    topics: [
      'components',
      'dom',
      'jsx',
      'preact',
      'react',
      'vdom',
      'virtual-dom',
    ],
    github_watchers: 425,
    has_projects: true,
    has_wiki: true,
    has_pages: true,
    closed_issues_count: 1309,
    open_pr_count: 78,
    closed_pr_count: 1729,
    week_issue_change: -12,
  },
  {
    id: 13142126,
    name: 'riot',
    full_name: 'riot/riot',
    html_url: 'https://github.com/riot/riot',
    rating: 'b',
    created_at: new Date('2013-09-27T05:21:01').toDateString(),
    updated_at: new Date('2021-12-20T05:17:31').toDateString(),
    pushed_at: new Date('2021-12-17T20:09:25').toDateString(),
    homepage: 'https://riot.js.org',
    github_stars: 14597,
    language: 'JavaScript',
    forks_count: 1032,
    open_issues_count: 5,
    license: 'Other',
    topics: [
      'client-side',
      'customelement',
      'customelements',
      'customtags',
      'elegant',
      'framework',
      'javascript',
      'lite',
      'minimal',
      'simple',
      'view',
      'webcomponents',
    ],
    github_watchers: 412,
    has_projects: true,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 2147,
    open_pr_count: 0,
    closed_pr_count: 755,
    week_issue_change: 0,
  },
  {
    id: 121594173,
    name: 'aurelia',
    full_name: 'aurelia/aurelia',
    html_url: 'https://github.com/aurelia/aurelia',
    rating: 'c',
    created_at: new Date('2018-02-15T05:22:58').toDateString(),
    updated_at: new Date('2021-12-19T04:23:43').toDateString(),
    pushed_at: new Date('2021-11-28T16:21:43').toDateString(),
    homepage: '',
    github_stars: 1142,
    language: 'TypeScript',
    forks_count: 121,
    open_issues_count: 143,
    license: 'MIT License',
    topics: [
      'aurelia',
      'cordova',
      'cross-platform',
      'electron',
      'framework',
      'frontend',
      'html',
      'javascript',
      'javascript-framework',
      'mobile',
      'pwa',
      'single-page-applications',
      'spa',
      'typescript',
      'web',
      'web-framework',
      'web-performance',
    ],
    github_watchers: 66,
    has_projects: true,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 214,
    open_pr_count: 17,
    closed_pr_count: 959,
    week_issue_change: 32,
  },
  {
    id: 70107786,
    name: 'next.js',
    full_name: 'vercel/next.js',
    html_url: 'https://github.com/vercel/next.js',
    rating: 'C',
    created_at: new Date('2016-10-05T23:32:51').toDateString(),
    updated_at: new Date('2021-12-20T08:57:47').toDateString(),
    pushed_at: new Date('2021-12-20T08:21:58').toDateString(),
    homepage: 'https://nextjs.org',
    github_stars: 78446,
    language: 'JavaScript',
    forks_count: 15787,
    open_issues_count: 1361,
    license: 'MIT License',
    topics: [
      'blog',
      'browser',
      'compiler',
      'components',
      'hybrid',
      'nextjs',
      'node',
      'react',
      'server-rendering',
      'ssg',
      'static',
      'static-site-generator',
      'universal',
      'vercel',
    ],
    github_watchers: 1224,
    has_projects: false,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 10320,
    open_pr_count: 254,
    closed_pr_count: 9849,
    week_issue_change: -63,
  },
  {
    id: 71995937,
    name: 'nuxt.js',
    full_name: 'nuxt/nuxt.js',
    html_url: 'https://github.com/nuxt/nuxt.js',
    rating: 'A',
    created_at: new Date('2016-10-26T11:18:47').toDateString(),
    updated_at: new Date('2021-12-20T08:27:45').toDateString(),
    pushed_at: new Date('2021-12-20T08:05:15').toDateString(),
    homepage: 'https://nuxtjs.org',
    github_stars: 38997,
    language: 'JavaScript',
    forks_count: 3157,
    open_issues_count: 464,
    license: 'Other',
    topics: [
      'framework',
      'isomorphic',
      'nuxt',
      'server-rendering',
      'ssr',
      'universal',
      'vue',
      'vue-router',
      'vuex',
      'web-app',
    ],
    github_watchers: 772,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 6129,
    open_pr_count: 30,
    closed_pr_count: 2869,
    week_issue_change: -18,
  },
  {
    id: 3214406,
    name: 'meteor',
    full_name: 'meteor/meteor',
    html_url: 'https://github.com/meteor/meteor',
    rating: 'B',
    created_at: new Date('2012-01-19T01:58:17').toDateString(),
    updated_at: new Date('2021-12-20T06:36:27').toDateString(),
    pushed_at: new Date('2021-12-17T18:10:08').toDateString(),
    homepage: 'https://www.meteor.com',
    github_stars: 42742,
    language: 'JavaScript',
    forks_count: 5187,
    open_issues_count: 120,
    license: 'Other',
    topics: [
      'build-system',
      'framework',
      'hacktoberfest',
      'javascript',
      'meteor',
      'mongodb',
      'nodejs',
      'npm',
      'reactive-programming',
      'zero-configuration',
    ],
    github_watchers: 1642,
    has_projects: true,
    has_wiki: true,
    has_pages: false,
    closed_issues_count: 8537,
    open_pr_count: 24,
    closed_pr_count: 2998,
    week_issue_change: 21,
  },
  {
    id: 43695474,
    name: 'quasar',
    full_name: 'quasarframework/quasar',
    html_url: 'https://github.com/quasarframework/quasar',
    rating: 'a',
    created_at: new Date('2015-10-05T15:45:36').toDateString(),
    updated_at: new Date('2021-12-20T08:26:07').toDateString(),
    pushed_at: new Date('2021-12-19T23:18:50').toDateString(),
    homepage: 'https://quasar.dev',
    github_stars: 20095,
    language: 'JavaScript',
    forks_count: 2543,
    open_issues_count: 367,
    license: 'MIT License',
    topics: [
      'android',
      'browser-extension',
      'electron',
      'ios',
      'javascript',
      'material',
      'material-components',
      'material-design',
      'material-theme',
      'pwa',
      'quasar-framework',
      'server-side-rendering',
      'ssr',
      'vue',
      'vue-component',
      'vue-components',
      'vue2',
      'vuejs',
      'vuejs2',
    ],
    github_watchers: 488,
    has_projects: false,
    has_wiki: false,
    has_pages: false,
    closed_issues_count: 6097,
    open_pr_count: 97,
    closed_pr_count: 3424,
    week_issue_change: 1,
  },
];
```

**`src/columnDefs.ts`**

```ts
import {ColDef} from 'ag-grid-enterprise';
import {WebFramework} from './rowData';

export const columnDefs: ColDef<WebFramework>[] = [
  {
    field: 'name',
    cellDataType: 'text',
    sortable: true,
  },
  {
    field: 'language',
    cellDataType: 'text',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'github_stars',
    headerName: 'GitHub Stars',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'github_watchers',
    headerName: 'GitHub Watchers',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'license',
    cellDataType: 'text',
    editable: false,
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'week_issue_change',
    headerName: 'Issue Change',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'created_at',
    headerName: 'Created',
    cellDataType: 'date',
  },
  {
    field: 'has_wiki',
    headerName: 'Has Wiki',
    cellDataType: 'boolean',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'updated_at',
    headerName: 'Updated',
    cellDataType: 'date',
  },
  {
    field: 'pushed_at',
    headerName: 'Pushed',
    cellDataType: 'date',
  },
  {
    field: 'rating',
    cellDataType: 'text',
    sortable: true,
  },
  {
    field: 'open_issues_count',
    headerName: 'Open Issues',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'closed_issues_count',
    headerName: 'Closed Issues',
    cellDataType: 'number',
    enableValue: true,
  },

  {
    field: 'open_pr_count',
    headerName: 'Open PRs',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'closed_pr_count',
    headerName: 'Closed PRs',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'has_projects',
    headerName: 'Has Projects',
    cellDataType: 'boolean',
  },
  {
    field: 'has_pages',
    headerName: 'Has Pages',
    cellDataType: 'boolean',
  },
  {
    field: 'topics',
    cellDataType: 'textArray',
    editable: false,
    sortable: false,
  },
  {
    field: 'id',
    cellDataType: 'number',
    hide: true,
    editable: false,
  },
];
```

## Using Custom Sorts

Run-time users can create, edit, delete, share and suspend Custom Sorts.

This is done using the Custom Sort section of the [Settings Panel](https://www.adaptabletools.com/docs/ui-settings-panel/index.md).

- The AdapTable UI **only** deals with List-based Custom Sorts
- Custom Sort Comparers are design-time objects only and not editable, shareable or suspendable at run-time

### Using the Custom Sort Wizard

There are just 3 steps involved when creating a Custom Sort

Choose a unique name for the Custom Sort

AdapTable will list all the Columns for which there is no existing Custom Sort.

Select the Column you require.

Unlike [Custom Sort comparers](https://www.adaptabletools.com/docs/technical-reference-custom-sorting/index.md) which use full [Scope](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md), list-based sorts are restricted to a single column

AdapTable will list all the **distinct values** for the column selected in the previous step.

Choose the column values you want in your Custom Sort and drag them to order as required.
