SortModel
Defined in: api/node/typescript/models.ts:663 ↗
SortModel acts as an adapter model for a given source model by sorting all its
rows according to the order given by compareFunction.
Note that, like FilterModel, the SortModel does not automatically observe modifications made directly to the source model. After such a modification, call SortModel.reset to re-apply the sort order and refresh the sorted view. Modifications made through SortModel.setRowData are reflected automatically.
Calling SortModel.setRowData while the cached sort order is stale (i.e. after the source model was mutated directly without a following SortModel.reset) does not just return stale reads — it writes to whatever source row the stale order points at, which may no longer be the row the caller intended. Always call SortModel.reset after a direct source mutation before calling SortModel.setRowData again.
Example
Section titled “Example”const source = new ArrayModel(["lorem", "ipsum", "dolor"]);const sorted = new SortModel(source, (a, b) => a.localeCompare(b));
// prints dolor, ipsum, loremfor (const x of sorted) { console.log(x);}Extends
Section titled “Extends”Model<T>
Type Parameters
Section titled “Type Parameters”T
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SortModel<
T>(sourceModel,compareFunction):SortModel<T>
Defined in: api/node/typescript/models.ts:678 ↗
Constructs a new SortModel that provides a sorted view on the given
sourceModel by applying the order given by compareFunction.
Parameters
Section titled “Parameters”sourceModel
Section titled “sourceModel”Model<T>
the wrapped model.
compareFunction
Section titled “compareFunction”(a, b) => number
compares two rows the same way the callback passed to Array.prototype.sort does.
Returns
Section titled “Returns”SortModel<T>
Overrides
Section titled “Overrides”Model<T>.constructor
Properties
Section titled “Properties”sourceModel
Section titled “sourceModel”
readonlysourceModel:Model<T>
Defined in: api/node/typescript/models.ts:667 ↗
The source model that this SortModel sorts rows from.
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
Iterator<T>
Defined in: api/node/typescript/models.ts:196 ↗
Returns
Section titled “Returns”Iterator<T>
Inherited from
Section titled “Inherited from”filter()
Section titled “filter()”filter(
filterFunction):FilterModel<T>
Defined in: api/node/typescript/models.ts:118 ↗
Returns a new Model that only contains the rows of this model for which
filterFunction returns true.
Parameters
Section titled “Parameters”filterFunction
Section titled “filterFunction”(data) => boolean
returns true if a row should be visible.
Returns
Section titled “Returns”FilterModel<T>
a new FilterModel that wraps the current model.
Inherited from
Section titled “Inherited from”insertRow()
Section titled “insertRow()”insertRow(
_index,_data):void
Defined in: api/node/typescript/models.ts:190 ↗
Implementations of this function must add a row at the specified index, pushing all next rows to the right.
Parameters
Section titled “Parameters”_index
Section titled “_index”number
index of the row to insert.
T
new data item to store in a new row.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”map<
U>(mapFunction):MapModel<T,U>
Defined in: api/node/typescript/models.ts:108 ↗
Returns a new Model where all elements are mapped by the function mapFunction.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”mapFunction
Section titled “mapFunction”(data) => U
maps the data from T to U.
Returns
Section titled “Returns”MapModel<T, U>
a new MapModel that wraps the current model.
Inherited from
Section titled “Inherited from”pushRow()
Section titled “pushRow()”pushRow(
_data):void
Defined in: api/node/typescript/models.ts:168 ↗
Implementations of this function must add a line to the model with the provided data.
Parameters
Section titled “Parameters”T
new data item to store in a new row.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”removeRow()
Section titled “removeRow()”removeRow(
_index):void
Defined in: api/node/typescript/models.ts:178 ↗
Implementations of this function must remove the row at the specified index.
Parameters
Section titled “Parameters”_index
Section titled “_index”number
index of the row to remove.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”reset()
Section titled “reset()”reset():
void
Defined in: api/node/typescript/models.ts:788 ↗
Re-applies the sort order on the rows of the source model and notifies the run-time that the sorted view has changed. Call this after modifying the source model directly, so that the sorted view reflects the current state of the source model.
Returns
Section titled “Returns”void
reverse()
Section titled “reverse()”reverse():
ReverseModel<T>
Defined in: api/node/typescript/models.ts:137 ↗
Returns a new Model with the same rows as this model, in reverse order.
Returns
Section titled “Returns”ReverseModel<T>
a new ReverseModel that wraps the current model.
Inherited from
Section titled “Inherited from”rowCount()
Section titled “rowCount()”rowCount():
number
Defined in: api/node/typescript/models.ts:730 ↗
Returns the number of entries in the sorted model.
Returns
Section titled “Returns”number
Overrides
Section titled “Overrides”rowData()
Section titled “rowData()”rowData(
row):T|undefined
Defined in: api/node/typescript/models.ts:739 ↗
Returns the data at the specified row.
Parameters
Section titled “Parameters”number
index in range 0..(rowCount() - 1).
Returns
Section titled “Returns”T | undefined
undefined if row is out of range otherwise the data.
Overrides
Section titled “Overrides”setRowData()
Section titled “setRowData()”setRowData(
row,data):void
Defined in: api/node/typescript/models.ts:760 ↗
Stores the given data in the source model at the row that corresponds to the given sorted row index, then re-reads it from the source model to find its new sorted position, notifying either a row change (position unchanged) or a row move (position changed) accordingly.
If the source model’s setRowData does not synchronously commit the
value read back by rowData (for example a read-only model that ignores
the write), the cached sort order may go out of sync; call
SortModel.reset in that case.
Parameters
Section titled “Parameters”number
index in range 0..(rowCount() - 1).
T
new data item to store on the given row index.
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”sort()
Section titled “sort()”sort(
compareFunction):SortModel<T>
Defined in: api/node/typescript/models.ts:129 ↗
Returns a new Model with the same rows as this model, ordered according to
compareFunction.
Parameters
Section titled “Parameters”compareFunction
Section titled “compareFunction”(a, b) => number
compares two rows the same way the callback passed to Array.prototype.sort does.
Returns
Section titled “Returns”SortModel<T>
a new SortModel that wraps the current model.
Inherited from
Section titled “Inherited from”unsortedRow()
Section titled “unsortedRow()”unsortedRow(
sortedRow):number|undefined
Defined in: api/node/typescript/models.ts:799 ↗
Given a sortedRow index into this SortModel, returns the corresponding
row index in the source model.
Parameters
Section titled “Parameters”sortedRow
Section titled “sortedRow”number
index in range 0..(rowCount() - 1).
Returns
Section titled “Returns”number | undefined
undefined if sortedRow is out of range otherwise the source row index.
© 2026 SixtyFPS GmbH