@mantlebee/ts-data
    Preparing search index...

    Class SortExtension<TItem>

    Keeps the list of sorts, optionally limited in number, and always sends it in the payload (an empty list means "no sort").

    const sorting = new SortExtension<User>(2); // two sorts at most
    sorting.addSort({ field: "lastName", asc: true });
    sorting.addSort({ field: "firstName", asc: true });
    sorting.addSort({ field: "age", asc: false }); // ignored: limit reached
    sorting.addSort({ field: "lastName", asc: false }); // replaces the sort on lastName, now last
    // payload.sorts: [firstName asc, lastName desc]

    Type Parameters

    • TItem = Any

      Type of the items.

    Hierarchy (View Summary)

    Implements

    Index
    _changeDelay: number
    _eventBus: EventBus<SortExtensionEvents<TItem>>

    Bus used to register handlers and to raise the events.

    _sorts: List<Sort<TItem>> = []
    _sortsLimit: number
    • Appends a sort, replacing the sort on the same field, if any (the replacement goes to the end, i.e. to the lowest priority). When the limit is reached and no sort is replaced, nothing changes but the events are raised anyway with the unchanged sorts.

      Parameters

      Returns void

    • Registers a handler for an event.

      Type Parameters

      • TKey extends string

        Name of the event to listen to.

      Parameters

      Returns IDisposable

      a subscription; dispose it to remove this single handler.