Final Class: GroupingDataProvider

Oracle® JavaScript Extension Toolkit (JET)
17.1.0

G12196-01

Module:
  • ojgroupingdataprovider

QuickNav

Description

This class implements TreeDataProvider. Wraps a flat DataProvider and groups the contents into tree data.


Usage

Signature:

final class GroupingDataProvider<K, D> implements TreeDataProvider<K, D>

Generic Parameters
ParameterDescription
KType of output key
DType of output data
Typescript Import Format
//This class is exported directly as module. To import it
import GroupingDataProvider= require("ojs/ojgroupingdataprovider");

For additional information visit:


Final classes in JET

Classes in JET are generally final and do not support subclassing. At the moment, final is not enforced. However, this will likely change in an upcoming JET release.


Constructor

new GroupingDataProvider(dataProvider, sortComparator, sectionRenderer, options)

Parameters:
Name Type Argument Description
dataProvider DataProvider.<K, D> The DataProvider to be wrapped.

This DataProvider must provide flat data that are sorted in some order.

sortComparator function(D, D): boolean The sort comparator function.

Given two data points, the sortComparator will return true if data2 should be sorted before data1 and false if data2 should be sorted after data1

sectionRenderer function(K): D The section renderer function

This function takes in a section key and returns data that will be provided to the view.

options GroupingDataProvider.Options.<D> <optional>
the optional parameters.

Methods

addEventListener(eventType: string, listener: EventListener): void

Add a callback function to listen for a specific event type.
Parameters:
Name Type Description
eventType string The event type to listen for.
listener EventListener The callback function that receives the event notification.

containsKeys(params: FetchByKeysParameters<K>): Promise<ContainsKeysResults<K>>

Check if rows are contained by keys (default: local dataset) FetchByKeysParameter scope may be set to "global" to check in global dataset
Parameters:
Name Type Description
params FetchByKeysParameters Fetch by keys parameters
Returns:

Promise which resolves to ContainsKeysResults

Type
Promise.<ContainsKeysResults>

dispatchEvent(evt: Event): boolean

Dispatch an event and invoke any registered listeners.
Parameters:
Name Type Description
event Event The event object to dispatch.
Returns:

Return false if a registered listener has cancelled the event. Return true otherwise.

Type
boolean

fetchByKeys(params: FetchByKeysParameters<K>): Promise<FetchByKeysResults<K, D>>

Fetch rows by keys (default: local dataset)
Parameters:
Name Type Description
params FetchByKeysParameters Fetch by keys parameters
Returns:

Promise which resolves to FetchByKeysResults

Type
Promise.<FetchByKeysResults>

fetchByOffset(params: FetchByOffsetParameters<D>): Promise<FetchByOffsetResults<K, D>>

Fetch rows by offset.
Parameters:
Name Type Description
params FetchByOffsetParameters Fetch by offset parameters
Returns:

Promise which resolves to FetchByOffsetResults

Type
Promise.<FetchByOffsetResults>

fetchFirst(parameters?: FetchListParameters<D>): AsyncIterable<FetchListResult<K, D>>

Get an AsyncIterable object for iterating the data.

AsyncIterable contains a Symbol.asyncIterator method that returns an AsyncIterator. AsyncIterator contains a “next” method for fetching the next block of data.

The "next" method returns a promise that resolves to an object, which contains a "value" property for the data and a "done" property that is set to true when there is no more data to be fetched. The "done" property should be set to true only if there is no "value" in the result. Note that "done" only reflects whether the iterator is done at the time "next" is called. Future calls to "next" may or may not return more rows for a mutable data source.

Please see the DataProvider documentation for more information on custom implementations.

Parameters:
Name Type Argument Description
params FetchListParameters <optional>
fetch parameters
See:
Returns:

AsyncIterable with FetchListResult

Type
AsyncIterable.<FetchListResult>
Example

Get an asyncIterator and then fetch first block of data by executing next() on the iterator. Subsequent blocks can be fetched by executing next() again.

let asyncIterator = dataprovider.fetchFirst(options)[Symbol.asyncIterator]();
let result = await asyncIterator.next();
let value = result.value;
let data = value.data;
let keys = value.metadata.map(function(val) {
  return val.key;
});
// true or false for done
let done = result.done;

getCapability(capabilityName?: string): any

Determines whether this DataProvider supports certain feature.
Parameters:
Name Type Description
capabilityName string capability name. Supported capability names are: "fetchByKeys", "fetchByOffset", and "sort".
Returns:

capability information or null if unsupported

Type
Object

getChildDataProvider(parentKey: any): GroupingDataProvider<K, D>

Get a data provider for the children of the row identified by parentKey.
Parameters:
Name Type Description
parentKey any key of the row to get child data provider for.
Returns:

An TreeDataProvider if the row can (but doesn't have to) have children; or null if the row cannot have children. Use the isEmpty method on the returned TreeDataProvider to determine if it currently has children.

Type
TreeDataProvider | null

getTotalSize : {Promise.<number>}

Gets the total size of the data set
Returns:

Returns a Promise which resolves to the total number of rows.

Type
Promise.<number>

isEmpty : {"yes"|"no"|"unknown"}

Return a string that indicates if this data provider is empty
Returns:

a string that indicates if this data provider is empty. Valid values are: "yes": this data provider is empty. "no": this data provider is not empty. "unknown": it is not known if this data provider is empty until a fetch is made.

Type
"yes" | "no" | "unknown"

removeEventListener(eventType: string, listener: EventListener): void

Remove a listener previously registered with addEventListener.
Parameters:
Name Type Description
eventType string The event type that the listener was registered for.
listener EventListener The callback function that was registered.

Type Definitions

Options<D>

Properties:
Name Type Argument Description
groupByStrategy function(D):Array.<string> The grouping mechanism.

Optional grouping mechanism. This allows for either a grouping function that will take in data and return a path Array of section keys from the root node to the item. The grouping mechanism can also be a string attribute of the data that will contain the path Array of section keys.

keyAttributes string | Array.<string> <optional>
Optional attribute name(s) which stores the key in the data.

Can be a string denoting a single key attribute or an array of strings for multiple key attributes. Dot notation can be used to specify nested attribute (e.g. 'attr.id').

If specified, caller must ensure that the keyAttributes contains values that are either unique within the entire tree, or unique among the siblings of each node. In the latter case, Caller must also set the keyAttributesScope option to 'siblings'.
If keyAttributes is specified and keyAttributesScope is 'global', the attribute value will be used as the key.
If keyAttributes is specified and keyAttributesScope is 'siblings', a path array of the attribute values, starting from the root node, will be used as the key.
If keyAttributes is not specified, a path array of node index, starting from the root node, will be used as the key.