Skip to content

Instantly share code, notes, and snippets.

@YonathanMeguira
Created January 20, 2021 16:07
Show Gist options
  • Save YonathanMeguira/86e3474a1fdeb9dfedbc4a8d324fe023 to your computer and use it in GitHub Desktop.
Save YonathanMeguira/86e3474a1fdeb9dfedbc4a8d324fe023 to your computer and use it in GitHub Desktop.
AG-grid: sorting for custom rendered colums
const myColDefs = [{
headerName: 'Header Name',
sortable: true,
cellRenderer: 'propName',
comparator: (valueA: any, valueB: any, nodeA: RowNode, nodeB: RowNode, isInverted: boolean) =>
sortColumnAlphabetically<User>('status', nodeA, nodeB)
}]
export function sortColumnAlphabetically<T>(key: keyof T, nodeA: any, nodeB: any): number {
const [valueA, valueB] = [nodeA.data[key], nodeB.data[key]];
return valueB.localeCompare(valueA);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment