Sorting Technical Reference

Summary

  • Custom Sorting is provided in 2 ways:
    • Through Custom Sort State (hardcoded values)
    • Via customSortComparers function in Custom Sort Options
  • Run-time access to Custom Sorting is via Custom Sort API
  • Grid API contains more general sorting functions
  • The Grid Sorted Event fires whenever sorting changes in AG Grid

Custom Sort State

The Custom Sort section of Initial Adaptable State contains a list of CustomSort objects:

Custom Sort Object

PropertyTypeDescription
CustomSortsCustomSort[]Collection of Custom Sort objects.

A CustomSort object contains simply a ColumnId and a list of values to use for the sort:

PropertyTypeDescription
ColumnIdstringId of Column on which Custom Sort will be applied
NamestringName of the Custom Sort definition
SortedValues(string | number)[]Order of values by which Column will be sorted; Date values are persisted as ISO strings ('yyyy-MM-dd')
IsReadOnlybooleanSets Entity to ReadOnly (overwriting a Strategy Entitlement of 'Full')
IsSuspendedbooleanSuspends (i.e. turns off) an Adaptable Object

Custom Sort Options

The Custom Sort Options is used to provide Custom Sort Comparers:

PropertyTypeDescription
customSortComparersColumnValuesComparer<TData>[]CustomSort column comparer functions

Custom Sort API

The Custom Sort API provides comprehensive programmatic access to Custom Sorting.

It includes these functions:

MethodReturnsDescription
addCustomSort(customSort)CustomSortAdds a Custom Sort to Custom Sort collection in Adaptable State
createCustomSort(params)CustomSortCreates new Custom Sort based on given values
deleteCustomSort(columnId)voidRemoves Custom Sort for a given ColumnId
editCustomSort(customSort)CustomSortEdits a Custom Sort
editCustomSortValues(columnId, values)CustomSortUpdates existing Custom Sort with new set of Sorted Values
getActiveCustomSorts(config)CustomSort[]Retrieves all Custom Sorts that are active (not-suspended) in Adaptable State
getCustomSortById(id, config)CustomSortRetrieves Custom Sort by the technical ID (from CustomSortState)
getCustomSortByName(name)CustomSort | undefinedRetrieves a Custom Sort by its Name
getCustomSortForColumn(columnId)CustomSort | undefinedRetrieves Custom Sort from Adaptable State for Column with given ColumnId
getCustomSorts(config)CustomSort[]Retrieves all Custom Sorts in Adaptable State
getCustomSortState()CustomSortStateRetrieves Custom Sort section from Adaptable State
getLiveCustomSortComparers()ColumnValuesComparer[]Returns all Custom Sort Comparers in Custom Sort Options that are currently applied
getLiveCustomSorts()CustomSort[]Retrieves all Custom Sorts in Adaptable State that are currently applied
getSuspendedCustomSorts(config)CustomSort[]Retrieves all Custom Sorts that are suspended in Adaptable State
openCustomSortSettingsPanel()voidOpens Settings Panel with Custom Sort section selected and visible
suspendAllCustomSort()voidSuspends all Custom Sorts
suspendCustomSort(customSort)CustomSortSuspends Custom Sort
unSuspendAllCustomSort()voidActivates all suspended Custom Sort
unSuspendCustomSort(customSort)CustomSortUn-suspends or activates a suspended Custom Sort

Grid Sorted Event

AdapTable fires the Grid Sorted Event whenever any column in AdapTable is sorted.

It provides information on what is being sorted in AdapTable.

Find Out More

This is often used when wanting to manage expressions on the Server

GridSortedInfo

The GridSortedInfo object provided by the event returns a single object:

PropertyTypeDescription
adaptableSortStateAdaptableSortStateCurrent sort state in the Grid
adaptableContextanyCustom application Context provided in AdaptableOptions.adaptableContext

The AdaptableSortState object provides information on what is being sorted in AdapTable.

PropertyTypeDescription
columnSortsColumnSort[]Columns currently being sorted (with direction)
customSortComparersColumnValuesComparer[]Custom Sort Comparers which are currently applied
customSortsCustomSort[]Custom Sorts which are currently applied

It contains 2 sections:

  • Column Sorts active in AG Grid
  • Custom Sorts which have been provided in Initial State (i.e. not supplied via Comparers)

Caution

Custom Sorts are always sent even if none are currently active

Event Subscription

Subscribing to the Event is done the same way as with all Adaptable Events:

api.eventApi.on('GridSorted', (eventInfo: GridSortedInfo) => {
    // do something with the info
});

Find Out More

There are also some sorting-related functions in Grid API