Interface: DataProviderOperationEventDetail

Oracle® JavaScript Extension Toolkit (JET)
9.2.0

F30740-01

Signature:

interface DataProviderOperationEventDetail<K, D>

QuickNav

Fields

DataProviderOperationEventDetail

Version:
  • 9.2.0
Since:
  • 4.2.0
Module:
  • ojdataprovider

Module usage

See JET Module Loading for an overview of module usage within JET.

Typescript Import Format
//To use this interface, import as below.
import {DataProviderOperationEventDetail} from "ojs/ojdataprovider";
Generic Parameters
ParameterDescription
KType of Key
DType of Data

JET In Typescript

A detailed description of working with JET elements and classes in your typescript project can be found at: JET Typescript Usage.

Description

Defines the details for a particular operation in an DataProviderMutationEventDetail

Fields

(nullable) data :D[]

Optional data of items involved in the operation
Since:
  • 4.2.0

(nullable) indexes :number[]

Optional indexes of items involved in the operation. Indices are with respect to the DataProvider with only its implicit sort applied. Essentially, indices are the global indices (except for TreeDataProvider, please see the note below), not the indices with respect to whatever query (which might have its own sorting or filtering) fetched the items.

For 'add' operation the indexes are relative to after the operation was completed and not the original dataset.

For 'update' operation the indexes are relative to after the operation was completed and not the original dataset.

For 'remove' operation the indexes are relative to the original dataset.

Note: With respect to TreeDataProvider, the index is the index at the level where the mutation occurs. That is, the index of the node among its siblings.

Optimization can be achieved by specifying indexes for mutation events.

Since:
  • 4.2.0
Examples

Example to illustrate indexes from array mutations

let data = [{ id: 1, name: 'Amy Bartlet', title: 'Vice President' },
            { id: 2, name: 'Annett Barnes', title: 'Individual  Contributer' },
            { id: 3, name: 'Bobby Fisher', title: 'Individual Contributer' }];
let observableArray = ko.observableArray(data);
let dataProvider = new ArrayDataProvider(ko.observableArray(data), { keyAttributes: 'id' });

let listener = function(event) {
 // Print DataProviderEventDetail
};

dataProvider.addEventListener("mutate", listener);

observableArray.push({ id: 4, name: ‘John schully', title: ‘Manager' });
// Then the DataProviderOperationEventDetail will have Indexes as [3]

observableArray.splice(2, 1, { id: 5, name: ’Scott Jhonson', title: ‘President' });
// Then the DataProviderOperationEventDetail will have Indexes as [2]

Example to illustrate indexes with respect to ArrayTreeDataProvider

let dataArray = [{
                   title: "Amy Bartlet",
                   id: "100"
                 },
                 {
                   title: "Scott Fisher",
                   id: "101",
                   children: [{
                                title: "John Fisher",
                                id: "102"
                              },
                              {
                                title: "Bobby Fisher",
                                id: "103"
                              }]
                 },
                 {
                   title: "Annett Barnes",
                   id: "104"
                 }];

createObservableArrayTree(data: Array) {
  let array = [];
  let observableArray = ko.observableArray(array);
  for (let i = 0; i < data.length; i++) {
    let newItem = data[i];
    if (data[i].children) {
      newItem.children = this.createObservableArrayTree(data[i].children);
    }
    observableArray.push(newItem);
  }
  return observableArray;
}

let observableArrayTree = createObservableArrayTree(dataArray);
let dataProvider = new ArrayTreeDataProvider(observableArrayTree, { keyAttributes: 'id' });
dataProvider.addEventListener('mutate', ((event: CustomEvent) => {
  console.log(event.detail);
}) as EventListener);
let index = 1;

observableArrayTree()[1].children.splice(index, 1);

// Output will be // { 'add': null, 'remove' : { 'indexes': [1] }, 'update': null}
// Here the index 1 refers to the object with id '103'.

keys :Set<K>

keys of items involved in the operation
Since:
  • 4.2.0

(nullable) metadata :Array.<ItemMetadata.<K>>

Optional metadata of items involved in the operation
Since:
  • 4.2.0