TinyBase logoTinyBase


The getResultSortedRowIds method returns the Ids of every ResultRow in the ResultTable of the given query, sorted according to the values in a specified ResultCell.

  queryId: string,
  cellId?: string,
  descending?: boolean,
  offset?: number,
  limit?: number,
): Ids

The Id of a query.


The Id of the ResultCell whose values are used for the sorting, or undefined to by sort the ResultRow Id itself.


Whether the sorting should be in descending order.


The number of ResultRow Ids to skip for pagination purposes, if any.


The maximum number of ResultRow Ids to return, or undefined for all.


An array of the sorted Ids of every ResultRow in the result of the query.

This has the same behavior as a Store's getSortedRowIds method. For example, if the query Id is invalid, the method returns an empty array. Similarly, the sorting of the rows is alphanumeric, and you can indicate whether it should be in descending order. The offset and limit parameters are used to paginate results, but default to 0 and undefined to return all available ResultRow Ids if not specified.

Note that every call to this method will perform the sorting afresh - there is no caching of the results - and so you are advised to memoize the results yourself, especially when the ResultTable is large. For a performant approach to tracking the sorted ResultRow Ids when they change, use the addResultSortedRowIdsListener method.


This example creates a Queries object, a single query definition, and then calls this method on it (as well as a non-existent definition) to get the ResultRow Ids.

const store = createStore().setTable('pets', {
  fido: {species: 'dog', color: 'brown'},
  felix: {species: 'cat', color: 'black'},
  cujo: {species: 'dog', color: 'black'},

const queries = createQueries(store).setQueryDefinition(
  ({select, where}) => {
    where('species', 'dog');

console.log(queries.getResultSortedRowIds('dogColors', 'color'));
// -> ['cujo', 'fido']

console.log(queries.getResultSortedRowIds('catColors', 'color'));
// -> []