TinyBase logoTinyBase


The getResultSortedRowIds method returns the Ids of every Row in the result Table of the given query, sorted according to the values in a specified Cell.

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

The Id of a query.


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


Whether the sorting should be in descending order.


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


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


An array of the sorted Ids of every Row 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 Row 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 result Table is large. For a performant approach to tracking the sorted Row 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 result Row 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'));
// -> []