Interface Dataset<IdType>

A data set represents a subset of items of a data source. It provides access to full displayable data.

The dataSource property is the source of the available data and in most cases an instance of a store.

You can watch the properties title, itemCount, state, initError and updateError for changes.

 const dataset = ...;
dataset.watch("state", ({value})=> {
const newState = value;
// newState can be: "not-initialized" | "initializing" | "initialized" | "init-error" | "destroyed" | "updating"
});

You can watch for the events items-changed, destroyed.

const dataset = ...;
dataset.on("items-changed", ({added, deleted, updated})=> { ... });
dataset.on("destroyed",()=> { ... });
interface Dataset<IdType extends DatasetItemId = DatasetItemId> {
    addItemsById(itemIds: Iterable<IdType>): Promise<void>;
    addItemsByIdsProvider(idsProvider: DatasetItemIdsProvider): Promise<void>;
    capabilities: DatasetCapabilities;
    clean(): Promise<void>;
    dataSource: unknown;
    dataSourceProperties: undefined | Readonly<Record<string, unknown>>;
    destroy(): void;
    fields: readonly FieldData[];
    id: string;
    init(): void;
    initError: undefined | Error;
    initialIdsProvider: undefined | DatasetItemIdsProvider;
    isDomainValueField(fieldName: string): boolean;
    isInitialized(): boolean;
    itemCount: ItemCount;
    lookupDomainValues(fieldValues: Record<string, any>): Record<string, any>;
    on<Name extends keyof DatasetEvents<IdType>>(
        name: Name,
        callBack: EventCallback<DatasetEvents<IdType>[Name]>,
    ): Handle;
    queryAllIds(): QueryResult<IdType>;
    queryItems(
        query: QueryDefinition<IdType>,
    ): QueryResult<DatasetItem<IdType>>;
    refresh(): Promise<void>;
    removeItemsById(itemIds: Iterable<IdType>): Promise<void>;
    replaceItemsByIdsProvider(
        idsProvider: DatasetItemIdsProvider,
    ): Promise<void>;
    state: DatasetState;
    title: string;
    updateError: undefined | Error;
    updateItemsById(itemIds: Iterable<IdType>): Promise<void>;
}

Type Parameters

Hierarchy

Properties

capabilities: DatasetCapabilities

Capabilities of the data set. The capabilities are only readable if the dataset is "initialized".

dataSource: unknown

The real data source.

dataSourceProperties: undefined | Readonly<Record<string, unknown>>

Service metadata about the data source if provided.

fields: readonly FieldData[]

The fields of the data set. The fields are only readable if the dataset is "initialized".

id: string

Dataset id. Typically initialized and equal to id of data source (store id).

initError: undefined | Error

A initialization error. Is available if state === "init-error".

initialIdsProvider: undefined | DatasetItemIdsProvider

Provides access to the initial id provider, if not yet used to init the dataset.

itemCount: ItemCount

The amount of items in the dataset. The itemCount is only readable if the dataset is "initialized".

The current state of the dataset.

title: string

Changeable title. Typically initialized from data source.

updateError: undefined | Error

A update error. This error may happen if an updating process failed.

Methods

  • Adds the given items to the dataset. Before using this method check the DatasetCapabilities.supportsAddItems State. If supportsAddItems is false, the method will throw an error.

    Parameters

    • itemIds: Iterable<IdType>

      Ids which will be added to the Dataset.

    Returns Promise<void>

  • Removes any data from the dataset.

    Returns Promise<void>

  • Destroys the dataset.

    Returns void

  • Starts dataset initialization.

    Returns void

  • Provides a way to check if the values of a field can be converted into domain values.

    Parameters

    • fieldName: string

      name of a field.

    Returns boolean

    true if the values can be converted.

  • Returns true if the dataset is in state initialized or updating

    Returns boolean

  • Provides a way to convert the values of a data set item into a domain values. Note to ensure that the method is working correctly the values of all domain fields should be provided.

    Parameters

    • fieldValues: Record<string, any>

      fields and the matching values.

    Returns Record<string, any>

    converted values or the original value if not convertible.

  • Enforces the refresh of the data. It may completely re-fetch item data and drop no longer existing items.

    Equivalent to:

      const allIds = await dataset.queryAllIds().toArray();
    dataset.updateItemsById(allIds);

    Returns Promise<void>

  • Removes the given items from the dataset. Before using this method check the DatasetCapabilities.supportsRemoveItems State. If supportsRemoveItems is false, the method will throw an error.

    Parameters

    • itemIds: Iterable<IdType>

      Ids which should be deleted from the dataset.

    Returns Promise<void>

  • Replaces all items in the dataset by the items provided by the ids provider. All items not longer provided by the ids provider will be removed from the dataset.

    Parameters

    Returns Promise<void>

  • Enforces the refresh of data of the given items. Note: If one of the ids did not exist, then it is ignored.

    Parameters

    • itemIds: Iterable<IdType>

      Ids which data will be updated.

    Returns Promise<void>