UNPKG

igniteui-webcomponents-datasources

Version:

Reference custom data providers for the Ignite UI Web Components data source.

68 lines (67 loc) 2.38 kB
import { DataSourceSchemaPropertyType } from "igniteui-webcomponents-core"; export class ODataDataSourcePage { constructor(sourceData_, schema, groupInformation, summaryInformation, pageIndex) { this._actualData = null; this._schema = null; this._pageIndex = 0; this._groupInformation = null; this._summaryInformation = null; if (sourceData_ == null) { this._actualData = null; } else { let count = (sourceData_.value.length); this._actualData = []; let dateProps = new Set(); for (let i = 0; i < schema.propertyNames.length; i++) { if (schema.propertyTypes[i] == DataSourceSchemaPropertyType.DateTimeValue || schema.propertyTypes[i] == DataSourceSchemaPropertyType.DateTimeOffsetValue) { dateProps.add(schema.propertyNames[i]); } } let value_; for (let i_ = 0; i_ < count; i_++) { let currItem_ = sourceData_.value[i_]; let dict = new Map(); let properties = Array.from(Object.keys(currItem_)); let values = (properties.map((k) => currItem_[k])); for (let i1 = 0; i1 < properties.length; i1++) { value_ = values[i1]; if (dateProps.has(properties[i1])) { value_ = new Date(value_); } dict.set(properties[i1], value_); } this._actualData[i_] = dict; } } this._schema = schema; this._groupInformation = groupInformation; this._summaryInformation = summaryInformation; this._pageIndex = pageIndex; } count() { return this._actualData.length; } getItemAtIndex(index) { return this._actualData[index]; } getItemValueAtIndex(index, valueName) { let item = this._actualData[index]; if (!item.has(valueName)) { return null; } return item.get(valueName); } pageIndex() { return this._pageIndex; } schema() { return this._schema; } getGroupInformation() { return this._groupInformation; } getSummaryInformation() { return this._summaryInformation; } }