@theredhead — Frontend Library - v1.0.0
    Preparing search index...

    Class SortableArrayDatasource<T>

    An in-memory array datasource that supports sorting via a comparator function.

    When a comparator is applied, the datasource re-derives its visible rows from the original data. The underlying array is never mutated.

    const ds = new SortableArrayDatasource(employees);
    ds.applyComparator((a, b) => a.age - b.age);

    Type Parameters

    • T

      The row object type.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    noteRowChanged: Emitter<RowChangedNotification> = ...

    Fires when a specific row has changed. The event includes the index of the changed row.

    noteRowRangeChanged: Emitter<RowRangeChangedNotification> = ...

    Fires when a range of rows has changed. The event includes the definition of the changed range.

    rows: T[]

    Accessors

    • get allRows(): readonly T[]

      The full, unsorted dataset.

      Useful when consumers need to inspect the original data while a sort is active.

      Returns readonly T[]

    Methods

    • Applies a comparator function to sort the datasource.

      Pass null or undefined to clear the sort and restore the original insertion order.

      Parameters

      • comparator: ((a: T, b: T) => number) | null | undefined

        The comparator function, or null/undefined to clear sorting.

      Returns void

    • Returns the row object at the given index.

      Parameters

      • rowIndex: number

        Zero-based index of the row to retrieve.

      Returns T

      The row value, or a Promise that resolves to it.

    • Inserts item at index, shifting subsequent items to the right.

      After this call, getNumberOfItems() must return one more than before, and getObjectAtRowIndex(index) must return the inserted item.

      Parameters

      • index: number

        The zero-based position at which to insert.

      • item: T

        The item to insert.

      Returns void

    • Moves the item at fromIndex to toIndex, shifting other items to accommodate.

      After this call, subsequent calls to getObjectAtRowIndex() and getNumberOfItems() must reflect the new order.

      Parameters

      • fromIndex: number

        The current zero-based index of the item to move.

      • toIndex: number

        The desired zero-based index for the item.

      Returns void

    • Notifies consumers that all visible data should be considered stale. Call this after bulk mutations that affect many rows.

      Returns void

    • Notifies consumers that the row at the given index has been externally mutated (e.g. property values changed in-place).

      Call this after directly modifying a row object so that any listening UI (such as a table view) can re-read the data.

      Parameters

      • rowIndex: number

        Zero-based index of the changed row.

      Returns void

    • Removes and returns the item at index, shifting subsequent items to the left.

      After this call, getNumberOfItems() must return one fewer than before.

      Parameters

      • index: number

        The zero-based position of the item to remove.

      Returns T

      The removed item.

    • Applies a serializable sort expression to the datasource.

      The expression is compiled into a comparator function internally. Pass null to clear the sort and restore the original insertion order.

      Parameters

      Returns void