Options
All
  • Public
  • Public/Protected
  • All
Menu

DataView

A DataView offers a filtered and/or formatted view on a DataSet. One can subscribe to changes in a DataView, and easily get filtered or formatted data without having to specify filters and field types all the time.

Example

// create a DataSet
var data = new vis.DataSet();
data.add([
{id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
{id: 2, text: 'item 2', date: '2013-06-23', group: 2},
{id: 3, text: 'item 3', date: '2013-06-25', group: 2},
{id: 4, text: 'item 4'}
]);

// create a DataView
// the view will only contain items having a property group with value 1,
// and will only output fields id, text, and date.
var view = new vis.DataView(data, {
filter: function (item) {
return (item.group == 1);
},
fields: ['id', 'text', 'date']
});

// subscribe to any change in the DataView
view.on('*', function (event, properties, senderId) {
console.log('event', event, properties);
});

// update an item in the data set
data.update({id: 2, group: 1});

// get all ids in the view
var ids = view.getIds();
console.log('ids', ids); // will output [1, 2]

// get all items in the view
var items = view.get();

Type Parameters

  • Item extends PartItem<IdProp>

    Item type that may or may not have an id.

  • IdProp extends string = "id"

    Name of the property that contains the id.

Hierarchy

  • DataSetPart<Item, IdProp>
    • DataView

Implements

Index

Constructors

  • Create a DataView.

    Type Parameters

    • Item extends Partial<Record<IdProp, OptId>>

    • IdProp extends string = "id"

    Parameters

    • data: DataInterface<Item, IdProp>

      The instance containing data (directly or indirectly).

    • Optional options: DataViewOptions<Item, IdProp>

      Options to configure this data view.

    Returns DataView<Item, IdProp>

Properties

_data: any
_ids: any
_listener: any
_onEvent: any

Event listener. Will propagate all events from the connected data set to the subscribers of the DataView, but will filter the items and only trigger when there are changes in the filtered data set.

param event

The name of the event.

param params

Parameters of the event.

param senderId

Id supplied by the sender.

_options: any
length: number

The number of items.

subscribe: { (event: "*", callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)): void; (event: "add", callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)): void; (event: "remove", callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void; (event: "update", callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void }

Type declaration

    • (event: "*", callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)): void
    • (event: "add", callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)): void
    • (event: "remove", callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
    • (event: "update", callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
    • inheritdoc

      Parameters

      • event: "*"
      • callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)
          • <N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id): void
          • Type Parameters

            Parameters

            • name: N

              The name of the event (EventName).

            • payload: EventPayloads<Item, IdProp>[N]

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

    • inheritdoc

      Parameters

      • event: "add"
      • callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)
          • (name: "add", payload: null | AddEventPayload, senderId?: null | Id): void
          • Parameters

            • name: "add"

              The name of the event (EventName).

            • payload: null | AddEventPayload

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

    • inheritdoc

      Parameters

      • event: "remove"
      • callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)
          • (name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id): void
          • Parameters

            • name: "remove"

              The name of the event (EventName).

            • payload: null | RemoveEventPayload<Item, IdProp>

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

    • inheritdoc

      Parameters

      • event: "update"
      • callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)
          • (name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id): void
          • Parameters

            • name: "update"

              The name of the event (EventName).

            • payload: null | UpdateEventPayload<Item, IdProp>

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

unsubscribe: { (event: "*", callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)): void; (event: "add", callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)): void; (event: "remove", callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void; (event: "update", callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void }

Type declaration

    • (event: "*", callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)): void
    • (event: "add", callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)): void
    • (event: "remove", callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
    • (event: "update", callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
    • inheritdoc

      Parameters

      • event: "*"
      • callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)
          • <N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id): void
          • Type Parameters

            Parameters

            • name: N

              The name of the event (EventName).

            • payload: EventPayloads<Item, IdProp>[N]

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

    • inheritdoc

      Parameters

      • event: "add"
      • callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)
          • (name: "add", payload: null | AddEventPayload, senderId?: null | Id): void
          • Parameters

            • name: "add"

              The name of the event (EventName).

            • payload: null | AddEventPayload

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

    • inheritdoc

      Parameters

      • event: "remove"
      • callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)
          • (name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id): void
          • Parameters

            • name: "remove"

              The name of the event (EventName).

            • payload: null | RemoveEventPayload<Item, IdProp>

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

    • inheritdoc

      Parameters

      • event: "update"
      • callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)
          • (name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id): void
          • Parameters

            • name: "update"

              The name of the event (EventName).

            • payload: null | UpdateEventPayload<Item, IdProp>

              Data about the items affected by this event.

            • Optional senderId: null | Id

              A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

            Returns void

      Returns void

Accessors

  • get idProp(): IdProp
  • get testLeakSubscribers(): any
  • Returns any

Methods

  • _trigger(event: "add", payload: AddEventPayload, senderId?: null | Id): void
  • _trigger(event: "update", payload: UpdateEventPayload<Item, IdProp>, senderId?: null | Id): void
  • _trigger(event: "remove", payload: RemoveEventPayload<Item, IdProp>, senderId?: null | Id): void
  • Parameters

    • event: "add"
    • payload: AddEventPayload
    • Optional senderId: null | Id

    Returns void

  • Parameters

    • event: "update"
    • payload: UpdateEventPayload<Item, IdProp>
    • Optional senderId: null | Id

    Returns void

  • Parameters

    • event: "remove"
    • payload: RemoveEventPayload<Item, IdProp>
    • Optional senderId: null | Id

    Returns void

  • dispose(): void
  • Render the instance unusable prior to garbage collection.

    remarks

    The intention of this method is to help discover scenarios where the data view is being used when the programmer thinks it has been garbage collected already. It's stricter version of dataView.setData(null).

    Returns void

  • forEach(callback: ((item: Item, id: Id) => void), options?: DataInterfaceForEachOptions<Item>): void
  • Execute a callback function for each item.

    remarks

    No guarantee is given about the order of iteration unless an ordering function is supplied.

    Parameters

    • callback: ((item: Item, id: Id) => void)

      Executed in similar fashion to Array.forEach callback, but instead of item, index, array receives item, id.

        • (item: Item, id: Id): void
        • Parameters

          • item: Item
          • id: Id

          Returns void

    • Optional options: DataInterfaceForEachOptions<Item>

      Options to specify iteration details.

    Returns void

  • Get all the items.

    inheritdoc

    Returns FullItem<Item, IdProp>[]

    An array containing all the items.

  • Get all the items.

    inheritdoc

    Parameters

    Returns FullItem<Item, IdProp>[]

    An array containing requested items.

  • Get all the items.

    inheritdoc

    Parameters

    Returns Record<Id, FullItem<Item, IdProp>>

    An object map of items (may be an empty object if there are no items).

  • Get all the items.

    inheritdoc

    Parameters

    Returns FullItem<Item, IdProp>[] | Record<Id, FullItem<Item, IdProp>>

    An array containing requested items or if requested an object map of items (may be an empty object if there are no items).

  • Get one item.

    inheritdoc

    Parameters

    • id: Id

      The id of the item.

    Returns null | FullItem<Item, IdProp>

    The item or null if the id doesn't correspond to any item.

  • Get one item.

    inheritdoc

    Parameters

    Returns null | FullItem<Item, IdProp>

    The item or null if the id doesn't correspond to any item.

  • Get one item.

    inheritdoc

    Parameters

    Returns Record<Id, FullItem<Item, IdProp>>

    An object map of items (may be an empty object if no item was found).

  • Get one item.

    inheritdoc

    Parameters

    Returns null | FullItem<Item, IdProp> | Record<Id, FullItem<Item, IdProp>>

    The item if found or null otherwise. If requested an object map with 0 to 1 items.

  • Get multiple items.

    inheritdoc

    Parameters

    • ids: Id[]

      An array of requested ids.

    Returns FullItem<Item, IdProp>[]

    An array of found items (ids that do not correspond to any item are omitted).

  • Get multiple items.

    inheritdoc

    Parameters

    Returns FullItem<Item, IdProp>[]

    An array of found items (ids that do not correspond to any item are omitted).

  • Get multiple items.

    inheritdoc

    Parameters

    Returns Record<Id, FullItem<Item, IdProp>>

    An object map of items (may be an empty object if no item was found).

  • Get multiple items.

    inheritdoc

    Parameters

    Returns FullItem<Item, IdProp>[] | Record<Id, FullItem<Item, IdProp>>

    An array of found items (ids that do not correspond to any item are omitted). If requested an object map of items (may be an empty object if no item was found).

  • Get items.

    inheritdoc

    Parameters

    • ids: Id | Id[]

      Id or ids to be returned.

    • Optional options: DataInterfaceGetOptions<Item>

      Options to specify iteration details.

    Returns null | FullItem<Item, IdProp> | FullItem<Item, IdProp>[] | Record<Id, FullItem<Item, IdProp>>

    The items (format is determined by ids (single or array) and the options.

  • getDataSet(): DataSet<Item, IdProp>
  • Get the DataSet to which the instance implementing this interface is connected. In case there is a chain of multiple DataViews, the root DataSet of this chain is returned.

    Returns DataSet<Item, IdProp>

    The data set that actually contains the data.

  • Get ids of items.

    remarks

    No guarantee is given about the order of returned ids unless an ordering function is supplied.

    Parameters

    Returns Id[]

    An array of requested ids.

  • Map each item into different item and return them as an array.

    remarks

    No guarantee is given about the order of iteration even if ordering function is supplied (the items are sorted after the mapping).

    Type Parameters

    • T

    Parameters

    • callback: ((item: Item, id: Id) => T)

      Array.map-like callback, but only with the first two params.

        • (item: Item, id: Id): T
        • Parameters

          • item: Item
          • id: Id

          Returns T

    • Optional options: DataInterfaceMapOptions<Item, T>

      Options to specify iteration details.

    Returns T[]

    The mapped items.

  • off(event: "*", callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)): void
  • off(event: "add", callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)): void
  • off(event: "remove", callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
  • off(event: "update", callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
  • Remove a universal event listener.

    inheritdoc

    Parameters

    • event: "*"

      Event name.

    • callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)

      Callback function.

        • <N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id): void
        • Type Parameters

          Parameters

          • name: N

            The name of the event (EventName).

          • payload: EventPayloads<Item, IdProp>[N]

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • Remove an add event listener.

    inheritdoc

    Parameters

    • event: "add"

      Event name.

    • callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)

      Callback function.

        • (name: "add", payload: null | AddEventPayload, senderId?: null | Id): void
        • Parameters

          • name: "add"

            The name of the event (EventName).

          • payload: null | AddEventPayload

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • Remove a remove event listener.

    inheritdoc

    Parameters

    • event: "remove"

      Event name.

    • callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)

      Callback function.

        • (name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id): void
        • Parameters

          • name: "remove"

            The name of the event (EventName).

          • payload: null | RemoveEventPayload<Item, IdProp>

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • Remove an update event listener.

    inheritdoc

    Parameters

    • event: "update"

      Event name.

    • callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)

      Callback function.

        • (name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id): void
        • Parameters

          • name: "update"

            The name of the event (EventName).

          • payload: null | UpdateEventPayload<Item, IdProp>

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • on(event: "*", callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)): void
  • on(event: "add", callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)): void
  • on(event: "remove", callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
  • on(event: "update", callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)): void
  • Add a universal event listener.

    remarks

    The * event is triggered when any of the events add, update, and remove occurs.

    Parameters

    • event: "*"

      Event name.

    • callback: (<N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id) => void)

      Callback function.

        • <N>(name: N, payload: EventPayloads<Item, IdProp>[N], senderId?: null | Id): void
        • Type Parameters

          Parameters

          • name: N

            The name of the event (EventName).

          • payload: EventPayloads<Item, IdProp>[N]

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • Add an add event listener.

    remarks

    The add event is triggered when an item or a set of items is added, or when an item is updated while not yet existing.

    Parameters

    • event: "add"

      Event name.

    • callback: ((name: "add", payload: null | AddEventPayload, senderId?: null | Id) => void)

      Callback function.

        • (name: "add", payload: null | AddEventPayload, senderId?: null | Id): void
        • Parameters

          • name: "add"

            The name of the event (EventName).

          • payload: null | AddEventPayload

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • Add a remove event listener.

    remarks

    The remove event is triggered when an item or a set of items is removed.

    Parameters

    • event: "remove"

      Event name.

    • callback: ((name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id) => void)

      Callback function.

        • (name: "remove", payload: null | RemoveEventPayload<Item, IdProp>, senderId?: null | Id): void
        • Parameters

          • name: "remove"

            The name of the event (EventName).

          • payload: null | RemoveEventPayload<Item, IdProp>

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • Add an update event listener.

    remarks

    The update event is triggered when an existing item or a set of existing items is updated.

    Parameters

    • event: "update"

      Event name.

    • callback: ((name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id) => void)

      Callback function.

        • (name: "update", payload: null | UpdateEventPayload<Item, IdProp>, senderId?: null | Id): void
        • Parameters

          • name: "update"

            The name of the event (EventName).

          • payload: null | UpdateEventPayload<Item, IdProp>

            Data about the items affected by this event.

          • Optional senderId: null | Id

            A senderId, optionally provided by the application code which triggered the event. If senderId is not provided, the argument will be null.

          Returns void

    Returns void

  • refresh(): void
  • Refresh the DataView. Useful when the DataView has a filter function containing a variable parameter.

    Returns void

  • Set a data source for the view.

    remarks

    Note that when the data view is bound to a data set it won't be garbage collected unless the data set is too. Use dataView.setData(null) or dataView.dispose() to enable garbage collection before you lose the last reference.

    Parameters

    • data: DataInterface<Item, IdProp>

      The instance containing data (directly or indirectly).

    Returns void

  • Stream.

    Parameters

    • Optional ids: Iterable<Id>

      Ids of the items to be included in this stream (missing are ignored), all if omitted.

    Returns DataStream<Item>

    The data stream for this data set.

Generated using TypeDoc