Skip to content

Model

Defined in: api/node/typescript/models.ts:90

Model is the interface for feeding dynamic data into .slint views.

A model is organized like a table with rows of data. The fields of the data type T behave like columns.

T

the type of the model’s items.

As an example let’s see the implementation of ArrayModel

export class ArrayModel<T> extends Model<T> {
private a: Array<T>
constructor(arr: Array<T>) {
super();
this.a = arr;
}
rowCount() {
return this.a.length;
}
rowData(row: number) {
return this.a[row];
}
setRowData(row: number, data: T) {
this.a[row] = data;
this.notifyRowDataChanged(row);
}
push(...values: T[]) {
let size = this.a.length;
Array.prototype.push.apply(this.a, values);
this.notifyRowAdded(size, arguments.length);
}
remove(index: number, size: number) {
let r = this.a.splice(index, size);
this.notifyRowRemoved(index, size);
}
get length(): number {
return this.a.length;
}
values(): IterableIterator<T> {
return this.a.values();
}
entries(): IterableIterator<[number, T]> {
return this.a.entries()
}
}
js
  • Iterable<T>

[iterator](): Iterator<T>

Defined in: api/node/typescript/models.ts:196

Iterator<T>

Iterable.[iterator]


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.

(data) => boolean

returns true if a row should be visible.

FilterModel<T>

a new FilterModel that wraps the current model.


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.

number

index of the row to insert.

T

new data item to store in a new row.

void


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.

U

(data) => U

maps the data from T to U.

MapModel<T, U>

a new MapModel that wraps the current model.


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.

T

new data item to store in a new row.

void


removeRow(_index): void

Defined in: api/node/typescript/models.ts:178

Implementations of this function must remove the row at the specified index.

number

index of the row to remove.

void


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.

ReverseModel<T>

a new ReverseModel that wraps the current model.


abstract rowCount(): number

Defined in: api/node/typescript/models.ts:144

Implementations of this function must return the current number of rows.

number


abstract rowData(row): T | undefined

Defined in: api/node/typescript/models.ts:150

Implementations of this function must return the data at the specified row.

number

index in range 0..(rowCount() - 1).

T | undefined

undefined if row is out of range otherwise the data.


setRowData(_row, _data): void

Defined in: api/node/typescript/models.ts:158

Implementations of this function must store the provided data parameter in the model at the specified row.

number

index in range 0..(rowCount() - 1).

T

new data item to store on the given row index

void


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.

(a, b) => number

compares two rows the same way the callback passed to Array.prototype.sort does.

SortModel<T>

a new SortModel that wraps the current model.


© 2026 SixtyFPS GmbH