UNPKG

@syncfusion/ej2-pivotview

Version:

The pivot grid, or pivot table, is used to visualize large sets of relational data in a cross-tabular format, similar to an Excel pivot table.

818 lines 359 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { extend, Internationalization } from '@syncfusion/ej2-base'; import { isNullOrUndefined, SanitizeHtmlHelper } from '@syncfusion/ej2-base'; import { DataManager, Query } from '@syncfusion/ej2-data'; import { PivotUtil } from './util'; /** * PivotEngine is used to manipulate the relational or Multi-Dimensional data as pivoting values. */ /** @hidden */ var PivotEngine = /** @class */ (function () { function PivotEngine() { /** @hidden */ this.aggregatedValueMatrix = []; /** @hidden */ this.valueContent = []; /** @hidden */ this.formatFields = {}; /** @hidden */ this.groupingFieldsInfo = {}; /** @hidden */ this.dateFormatFunction = {}; /** @hidden */ this.calculatedFields = {}; /** @hidden */ this.calculatedFormulas = {}; /** @hidden */ this.valueAxis = 0; /** @hidden */ this.saveDataHeaders = {}; /** @hidden */ this.columnCount = 0; /** @hidden */ this.rowCount = 0; /** @hidden */ this.columnPageCount = 0; /** @hidden */ this.rowPageCount = 0; /** @hidden */ this.colFirstLvl = 0; /** @hidden */ this.rowFirstLvl = 0; /** @hidden */ this.rowStartPos = 0; /** @hidden */ this.colStartPos = 0; /** @hidden */ this.enableValueSorting = false; /** @hidden */ this.headerCollection = { rowHeaders: [], columnHeaders: [], rowHeadersCount: 0, columnHeadersCount: 0 }; /** @hidden */ this.lastMember = {}; /** @hidden */ this.rMembers = []; /** @hidden */ this.cMembers = []; /** @hidden */ this.groupingFields = {}; /** @hidden */ this.isLastHeaderHasMeasures = true; /** @hidden */ this.measureIndex = -1; /** @hidden */ this.isPagingOrVirtualizationEnabled = false; /** @hidden */ this.rowMaxLevel = 0; this.valueMatrix = []; this.memberCnt = -1; this.pageInLimit = false; this.endPos = 0; this.removeCount = 0; this.colHdrBufferCalculated = false; this.colValuesLength = 1; this.rowValuesLength = 1; this.slicedHeaders = []; this.fieldFilterMem = {}; this.filterPosObj = {}; this.selectedHeaders = { selectedHeader: [], values: [] }; this.rowGrandTotal = null; this.columnGrandTotal = null; this.removeRowGrandTotal = false; this.removeColumnGrandTotal = false; this.isValueHasAdvancedAggregate = false; this.rawIndexObject = {}; this.reformAxisCount = 0; this.isEditing = false; /** @hidden */ this.valueAxisFields = {}; /** @hidden */ this.data = []; /** @hidden */ this.actualData = []; /** @hidden */ this.groupRawIndex = {}; /** @hidden */ this.fieldKeys = {}; this.allowDataCompression = false; this.dataSourceSettings = {}; this.frameHeaderObjectsCollection = false; this.headerObjectsCollection = {}; this.columnKeys = {}; this.fieldDrillCollection = {}; this.formatRegex = /^(?:[ncpae])(?:([0-9]|1[0-9]|20))?$/i; this.measureNames = {}; this.enablePaging = false; this.enableVirtualization = false; this.enableHtmlSanitizer = false; this.enableOptimizedRendering = false; this.groupedDataType = {}; this.tabularPivotValues = []; this.sortMembers = {}; /** @hidden */ this.viewportPageCount = 3; /* private makeMirrorObject(elements: number[], obj: NumberIndex): void { for (let lp: number = 0, end: number = elements.length; lp < end; lp++) { obj[elements[lp]] = elements[lp]; } } */ } /** * It is used to clear properties. * * @param {boolean} isExport - It indicates whether it is triggered after the export or not. * @returns {void} * @hidden */ PivotEngine.prototype.clearProperties = function (isExport) { if (!this.isPagingOrVirtualizationEnabled && !isExport) { this.columnKeys = {}; this.headerCollection = { rowHeaders: [], columnHeaders: [], rowHeadersCount: 0, columnHeadersCount: 0 }; } if (this.enableValueSorting) { this.valueContent = []; } this.saveDataHeaders = this.allowValueFilter ? this.saveDataHeaders : {}; this.rMembers = []; this.cMembers = []; this.lastMember = {}; this.slicedHeaders = []; this.fieldFilterMem = {}; this.filterPosObj = {}; this.selectedHeaders = { selectedHeader: [], values: [] }; this.rowGrandTotal = null; this.columnGrandTotal = null; this.rawIndexObject = {}; if (this.dataSourceSettings.valueIndex > -1) { this.valueAxisFields = {}; } this.headerObjectsCollection = {}; this.fieldDrillCollection = {}; this.sortMembers = {}; }; /** * It is used to render the pivot engine. * * @param {IDataOptions} dataSource - It contains the dataSourceSettings. * @param {ICustomProperties} customProperties - It contains the custom Properties. * @param {Function} fn - It contains aggreagateCellnInfo method. * @param {Function} onHeadersSort - It contains onHeaderSort method. * @returns {void} * @hidden */ PivotEngine.prototype.renderEngine = function (dataSource, customProperties, fn, onHeadersSort) { this.getValueCellInfo = fn; this.getHeaderSortInfo = onHeadersSort; this.customProperties = customProperties; if (this.fieldList) { for (var i = 0, j = dataSource.formatSettings; i < j.length; i++) { if (!this.formatFields[j[i].name] && this.fieldList[j[i].name]) { this.fieldList[j[i].name].members = {}; this.fieldList[j[i].name].formattedMembers = {}; this.fieldList[j[i].name].dateMember = []; } } } this.formatFields = {}; this.dateFormatFunction = {}; this.calculatedFields = {}; this.calculatedFormulas = {}; this.valueAxis = 0; this.saveDataHeaders = {}; this.columnCount = 0; this.rowCount = 0; this.columnPageCount = 0; this.rowPageCount = 0; this.colFirstLvl = 0; this.rowFirstLvl = 0; this.rowStartPos = 0; this.colStartPos = 0; this.dataSourceSettings.excludeFields = isNullOrUndefined(dataSource.excludeFields) ? [] : dataSource.excludeFields; this.enableValueSorting = false; this.headerCollection = { rowHeaders: [], columnHeaders: [], rowHeadersCount: 0, columnHeadersCount: 0 }; this.aggregatedValueMatrix = []; this.rMembers = []; this.cMembers = []; this.memberCnt = -1; this.pageInLimit = false; this.endPos = 0; this.removeCount = 0; this.colHdrBufferCalculated = false; this.colValuesLength = 1; this.rowValuesLength = 1; this.slicedHeaders = []; this.fieldFilterMem = {}; this.filterPosObj = {}; this.selectedHeaders = { selectedHeader: [], values: [] }; this.rowGrandTotal = null; this.columnGrandTotal = null; this.removeRowGrandTotal = false; this.removeColumnGrandTotal = false; this.isValueHasAdvancedAggregate = false; this.rawIndexObject = {}; this.isLastHeaderHasMeasures = true; this.isEditing = false; var fields; this.globalize = (customProperties && customProperties.globalize) ? customProperties.globalize : new Internationalization(); this.currencyCode = (customProperties && customProperties.currenyCode) ? customProperties.currenyCode : undefined; this.localeObj = customProperties ? customProperties.localeObj : undefined; this.fieldsType = customProperties ? customProperties.fieldsType : {}; this.clonedReport = customProperties ? (customProperties.clonedReport && customProperties.clonedReport.properties ? customProperties.clonedReport.properties : customProperties.clonedReport) : {}; this.enablePaging = customProperties.enablePaging; this.enableVirtualization = customProperties.enableVirtualization; this.enableOptimizedRendering = customProperties.enableOptimizedRendering; this.enableHtmlSanitizer = customProperties.enableHtmlSanitizer; this.isPagingOrVirtualizationEnabled = this.enablePaging || this.enableVirtualization; this.enableSort = dataSource.enableSorting; this.dataSourceSettings.alwaysShowValueHeader = dataSource.alwaysShowValueHeader; this.dataSourceSettings.showHeaderWhenEmpty = isNullOrUndefined(dataSource.showHeaderWhenEmpty) ? true : dataSource.showHeaderWhenEmpty; this.dataSourceSettings.showSubTotals = isNullOrUndefined(dataSource.showSubTotals) ? true : dataSource.showSubTotals; this.dataSourceSettings.showRowSubTotals = isNullOrUndefined(dataSource.showRowSubTotals) ? true : dataSource.showRowSubTotals; this.dataSourceSettings.showColumnSubTotals = isNullOrUndefined(dataSource.showColumnSubTotals) ? true : dataSource.showColumnSubTotals; this.dataSourceSettings.showGrandTotals = isNullOrUndefined(dataSource.showGrandTotals) ? true : dataSource.showGrandTotals; this.dataSourceSettings.grandTotalsPosition = isNullOrUndefined(dataSource.grandTotalsPosition) ? 'Bottom' : dataSource.grandTotalsPosition; this.dataSourceSettings.showRowGrandTotals = isNullOrUndefined(dataSource.showRowGrandTotals) ? true : dataSource.showRowGrandTotals; this.dataSourceSettings.showColumnGrandTotals = isNullOrUndefined(dataSource.showColumnGrandTotals) ? true : dataSource.showColumnGrandTotals; this.showSubTotalsAtTop = (this.dataSourceSettings.showSubTotals && this.dataSourceSettings.showColumnSubTotals && dataSource.subTotalsPosition === 'Top'); this.showSubTotalsAtBottom = (this.dataSourceSettings.showSubTotals && this.dataSourceSettings.showRowSubTotals && dataSource.subTotalsPosition === 'Bottom') || customProperties.isTabularLayout; this.allowValueFilter = dataSource.allowValueFilter; this.isValueFilterEnabled = false; this.enableValueSorting = customProperties ? customProperties.enableValueSorting : false; this.isDrillThrough = customProperties ? (customProperties.isDrillThrough ? customProperties.isDrillThrough : false) : false; this.valueContent = []; this.dataSourceSettings = PivotUtil.getClonedDataSourceSettings(dataSource); if (!(dataSource.dataSource instanceof DataManager)) { if (dataSource.type === 'CSV') { this.data = dataSource.dataSource.map(function (innerArray) { return innerArray.slice(); }); if (this.fieldList) { this.data.shift(); } } else { this.data = dataSource.dataSource; } } if (this.data && this.data[0]) { if (!this.fieldList) { if (dataSource.type === 'CSV') { this.fields = this.data.shift(); } else { this.fields = Object.keys(this.data[0]); } this.fieldKeys = {}; for (var i = 0; i < this.fields.length; i++) { this.fieldKeys[this.fields[i]] = dataSource.type === 'CSV' ? i : this.fields[i]; } } if (customProperties && customProperties.pageSettings && customProperties.allowDataCompression) { this.actualData = this.data; this.data = this.getGroupedRawData(dataSource); } this.dataSourceSettings.rows = dataSource.rows ? dataSource.rows : []; this.dataSourceSettings.columns = dataSource.columns ? dataSource.columns : []; this.dataSourceSettings.filters = dataSource.filters ? dataSource.filters : []; this.dataSourceSettings.values = dataSource.values ? dataSource.values : []; this.dataSourceSettings.formatSettings = dataSource.formatSettings ? dataSource.formatSettings : []; this.dataSourceSettings.groupSettings = dataSource.groupSettings ? dataSource.groupSettings : []; this.dataSourceSettings.calculatedFieldSettings = dataSource.calculatedFieldSettings ? dataSource.calculatedFieldSettings : []; this.enableSort = dataSource.enableSorting === undefined ? true : dataSource.enableSorting; this.dataSourceSettings.fieldMapping = dataSource.fieldMapping ? dataSource.fieldMapping : []; this.valueAxisFields = {}; for (var _i = 0, _a = this.dataSourceSettings.values; _i < _a.length; _i++) { var value = _a[_i]; this.valueAxisFields[value.name] = value; } fields = this.getGroupData(this.data); this.validateFilters(dataSource); this.isExpandAll = (this.isValueFiltersAvail && dataSource.allowValueFilter) ? true : dataSource.expandAll; this.drilledMembers = dataSource.drilledMembers ? (this.isValueFiltersAvail && dataSource.allowValueFilter) ? [] : dataSource.drilledMembers : []; this.isMultiMeasures = this.dataSourceSettings.values.length > 1 ? true : false; this.valueAxis = dataSource.valueAxis === 'row' ? 1 : 0; this.measureIndex = !isNullOrUndefined(dataSource.valueIndex) ? dataSource.valueIndex : -1; this.emptyCellTextContent = dataSource.emptyCellsTextContent ? dataSource.emptyCellsTextContent : ''; this.rowValuesLength = this.valueAxis === 1 ? this.dataSourceSettings.values.length : 1; this.colValuesLength = this.valueAxis === 0 ? this.dataSourceSettings.values.length : 1; this.valueSortSettings = dataSource.valueSortSettings || { rowSortOrder: 'None', rowHeaderText: '', columnSortOrder: 'None', columnHeaderText: '', headerDelimiter: '.', columnIndex: undefined, rowIndex: undefined }; this.valueSortData = []; this.pageSettings = customProperties ? (customProperties.pageSettings ? customProperties.pageSettings : this.pageSettings) : undefined; this.allowDataCompression = customProperties && customProperties.allowDataCompression; this.savedFieldList = customProperties ? customProperties.savedFieldList : undefined; this.getFieldList(fields, this.enableSort, dataSource.allowValueFilter); this.removeIrrelevantFields(Object.keys(this.fieldList)); this.fillFieldMembers(); this.updateSortSettings(dataSource.sortSettings, this.enableSort); this.filterMembers = []; var columnLength = this.dataSourceSettings.columns.length - 1; this.columnKeys = {}; while (columnLength > -1) { this.columnKeys[this.dataSourceSettings.columns[columnLength].name] = this.dataSourceSettings .columns[columnLength]; columnLength--; } this.updateFilterMembers(dataSource); this.generateGridData(dataSource); } }; PivotEngine.prototype.removeIrrelevantFields = function (fields) { var report = {}; report[0] = this.dataSourceSettings.rows; report[1] = this.dataSourceSettings.columns; report[2] = this.dataSourceSettings.values; report[3] = this.dataSourceSettings.filters; var pos = 0; while (pos < 4) { if (report[pos]) { for (var cnt = 0; cnt < report[pos].length; cnt++) { var fieldName = report[pos][cnt].name; if ((this.dataSourceSettings.excludeFields.indexOf(fieldName) > -1) || (!isNullOrUndefined(fields) && fields.indexOf(fieldName) === -1)) { report[pos].splice(cnt, 1); cnt--; } else if (pos === 2) { this.measureNames[fieldName] = report[pos][cnt].caption ? report[pos][cnt].caption : fieldName; this.measureNames[report[pos][cnt].caption ? report[pos][cnt].caption : fieldName] = fieldName; } } } pos++; } this.isMultiMeasures = this.dataSourceSettings.values.length > 1 ? true : false; this.measureIndex = this.measureIndex === -1 ? (this.valueAxis ? report[0].length : report[1].length) : this.measureIndex; }; PivotEngine.prototype.updateDataSourceSettings = function (dataSource, requireDatasourceUpdate) { if (requireDatasourceUpdate) { this.emptyCellTextContent = dataSource.emptyCellsTextContent ? dataSource.emptyCellsTextContent : ''; this.valueAxis = dataSource.valueAxis === 'row' ? 1 : 0; this.rowValuesLength = this.valueAxis === 1 ? this.dataSourceSettings.values.length : 1; this.colValuesLength = this.valueAxis === 0 ? this.dataSourceSettings.values.length : 1; this.measureIndex = !isNullOrUndefined(dataSource.valueIndex) ? dataSource.valueIndex : -1; this.enableSort = dataSource.enableSorting; this.dataSourceSettings.alwaysShowValueHeader = dataSource.alwaysShowValueHeader; this.dataSourceSettings.showHeaderWhenEmpty = isNullOrUndefined(dataSource.showHeaderWhenEmpty) ? true : dataSource.showHeaderWhenEmpty; this.dataSourceSettings.showSubTotals = isNullOrUndefined(dataSource.showSubTotals) ? true : dataSource.showSubTotals; this.dataSourceSettings.showRowSubTotals = isNullOrUndefined(dataSource.showRowSubTotals) ? true : dataSource.showRowSubTotals; this.dataSourceSettings.showColumnSubTotals = isNullOrUndefined(dataSource.showColumnSubTotals) ? true : dataSource.showColumnSubTotals; this.dataSourceSettings.showGrandTotals = isNullOrUndefined(dataSource.showGrandTotals) ? true : dataSource.showGrandTotals; this.dataSourceSettings.grandTotalsPosition = isNullOrUndefined(dataSource.grandTotalsPosition) ? 'Bottom' : dataSource.grandTotalsPosition; this.dataSourceSettings.showRowGrandTotals = isNullOrUndefined(dataSource.showRowGrandTotals) ? true : dataSource.showRowGrandTotals; this.dataSourceSettings.showColumnGrandTotals = isNullOrUndefined(dataSource.showColumnGrandTotals) ? true : dataSource.showColumnGrandTotals; this.showSubTotalsAtTop = this.dataSourceSettings.showSubTotals && dataSource.subTotalsPosition === 'Top' && dataSource.showColumnSubTotals; this.showSubTotalsAtBottom = this.customProperties.isTabularLayout ? true : this.dataSourceSettings.showSubTotals && dataSource.subTotalsPosition === 'Bottom' && dataSource.showRowSubTotals; this.allowValueFilter = dataSource.allowValueFilter; this.dataSourceSettings.formatSettings = dataSource.formatSettings ? dataSource.formatSettings : []; this.dataSourceSettings.groupSettings = dataSource.groupSettings ? dataSource.groupSettings : []; this.dataSourceSettings.calculatedFieldSettings = dataSource.calculatedFieldSettings ? dataSource.calculatedFieldSettings : []; this.enableSort = dataSource.enableSorting === undefined ? true : dataSource.enableSorting; this.dataSourceSettings.fieldMapping = dataSource.fieldMapping ? dataSource.fieldMapping : []; this.dataSourceSettings.values = dataSource.values ? dataSource.values : []; this.dataSourceSettings.rows = dataSource.rows ? dataSource.rows : []; this.dataSourceSettings.columns = dataSource.columns ? dataSource.columns : []; this.dataSourceSettings.filters = dataSource.filters ? dataSource.filters : []; this.dataSourceSettings.filterSettings = dataSource.filterSettings ? dataSource.filterSettings : []; this.dataSourceSettings.sortSettings = dataSource.sortSettings ? dataSource.sortSettings : []; this.dataSourceSettings.conditionalFormatSettings = dataSource.conditionalFormatSettings ? dataSource.conditionalFormatSettings : []; this.dataSourceSettings.valueSortSettings = dataSource.valueSortSettings ? dataSource.valueSortSettings : {}; this.removeIrrelevantFields(Object.keys(this.fieldList)); } }; PivotEngine.prototype.getGroupedRawData = function (dataSourceSettings) { this.data = []; for (var _i = 0, _a = this.actualData; _i < _a.length; _i++) { var data = _a[_i]; this.data[this.data.length] = PivotUtil.frameHeaderWithKeys(data); } var countFields = dataSourceSettings.values.filter(function (item) { return item.type === 'Count' || item.type === 'DistinctCount'; }).map(function (item) { return item.name; }); var hasCountField = countFields.length > 0; var realData = this.data; var headerFields = dataSourceSettings.rows.concat(dataSourceSettings.columns.concat(dataSourceSettings.filters)).map(function (item) { return item.name; }); var groupRawData = {}; var finalData = []; this.groupRawIndex = {}; var groupKeys = {}; var indexLength = 0; for (var i = 0; i < realData.length; i++) { var currData = realData[i]; var members = []; if (hasCountField) { for (var vPos = 0; vPos < countFields.length; vPos++) { currData[this.fieldKeys[countFields[vPos]]] = isNullOrUndefined(currData[this.fieldKeys[countFields[vPos]]]) ? currData[this.fieldKeys[countFields[vPos]]] : 1; } } for (var hPos = 0; hPos < headerFields.length; hPos++) { members.push(currData[this.fieldKeys[headerFields[hPos]]]); } var memberJoin = members.join('-'); if (groupRawData[memberJoin]) { for (var vPos = 0; vPos < dataSourceSettings.values.length; vPos++) { var currFieldName = dataSourceSettings.values[vPos].name; var currValue = currData[this.fieldKeys[currFieldName]]; var savedData = groupRawData[memberJoin]; var summType = dataSourceSettings.values[vPos].type; if (!isNullOrUndefined(currValue)) { if (typeof currValue !== 'number' || summType === 'DistinctCount') { summType = 'Count'; } if (isNullOrUndefined(savedData[currFieldName])) { savedData[currFieldName] = summType === 'Product' ? 1 : ((summType === 'Min' || summType === 'Max') ? undefined : 0); } else if (typeof savedData[currFieldName] !== 'number') { savedData[currFieldName] = 1; } if (summType === 'Count') { savedData[currFieldName] += 1; } else if (summType === 'Min') { if (!isNullOrUndefined(savedData[currFieldName])) { savedData[currFieldName] = savedData[currFieldName] > currValue ? currValue : savedData[currFieldName]; } } else if (summType === 'Max') { if (!isNullOrUndefined(savedData[currFieldName])) { savedData[currFieldName] = savedData[currFieldName] < currValue ? currValue : savedData[currFieldName]; } } else if (summType === 'Product') { savedData[currFieldName] *= currValue; } else { savedData[currFieldName] += currValue; } } } if (this.isDrillThrough) { this.groupRawIndex[groupKeys[memberJoin]].push(i); } } else { (groupRawData)[memberJoin] = currData; finalData.push(currData); if (this.isDrillThrough) { this.groupRawIndex[indexLength] = [i]; groupKeys[memberJoin] = indexLength; indexLength++; } } } return finalData; }; PivotEngine.prototype.getGroupData = function (data) { var _this = this; var fieldkeySet = data[0]; var _loop_1 = function (i, groupElements) { var group = groupElements[i]; var fieldName = group.name; var caption = group.caption; if (this_1.fields.indexOf(fieldName) > -1) { var groupFields = {}; var customGroupFieldName = void 0; if ((group.type === 'Date' && this_1.groupingFields[fieldName]) || (group.type === 'Custom' && this_1.groupingFields[fieldName])) { return { value: fieldkeySet }; } else if (group.type === 'Number') { if (PivotUtil.getType(fieldkeySet[fieldName]) === 'number' || !this_1.groupingFields[fieldName]) { if (group.rangeInterval) { data.sort(function (a, b) { return (Number(a[_this.fieldKeys[fieldName]]) > Number(b[_this.fieldKeys[fieldName]])) ? 1 : ((Number(b[_this.fieldKeys[fieldName]]) > Number(a[_this.fieldKeys[fieldName]])) ? -1 : 0); }); } } else { return { value: fieldkeySet }; } } // else if (group.type === 'Custom' && this.fields.indexOf(fieldName + '_custom_group') > -1) { // return fieldkeySet; // } var len = data.length; while (len--) { var item = data[len]; if (item[this_1.fieldKeys[fieldName]] && group.type === 'Date') { var date = new Date(item[this_1.fieldKeys[fieldName]].toString()); if (!isNullOrUndefined(date) && group.groupInterval.length > 0) { for (var i_1 = 0, len_1 = group.groupInterval.length; i_1 < len_1; i_1++) { var interval = group.groupInterval[i_1]; var isInRangeAvail = this_1.getRange(group, date.getTime()); var newDate = PivotUtil.resetTime(new Date()); switch (interval) { case 'Years': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_years'; groupFields[newFieldName] = interval; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : new Date(newDate.setFullYear(date.getFullYear())).toString()); } break; case 'Quarters': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_quarters'; groupFields[newFieldName] = interval; var month = Math.ceil((date.getMonth() + 1) / 3); this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : ((this_1.localeObj ? this_1.localeObj.getConstant('qtr') : 'Qtr') + month.toString())); } break; case 'QuarterYear': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_quarterYear'; groupFields[newFieldName] = interval; var month = Math.ceil((date.getMonth() + 1) / 3); this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : ((this_1.localeObj ? this_1.localeObj.getConstant('qtr') : 'Qtr') + month.toString() + ' ' + (this_1.localeObj ? this_1.localeObj.getConstant('of') : 'of') + ' ' + date.getFullYear().toString())); } break; case 'Months': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_months'; groupFields[newFieldName] = interval; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : new Date(newDate.setMonth(date.getMonth(), 1)).toString()); } break; case 'Days': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_days'; groupFields[newFieldName] = interval; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : new Date(newDate.setMonth(date.getMonth(), date.getDate())).toString()); } break; case 'Hours': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_hours'; groupFields[newFieldName] = interval; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : new Date(newDate.setHours(date.getHours())).toString()); } break; case 'Minutes': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_minutes'; groupFields[newFieldName] = interval; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : new Date(newDate.setMinutes(date.getMinutes())).toString()); } break; case 'Seconds': { var newFieldName = (i_1 === group.groupInterval.length - 1) ? fieldName : fieldName + '_date_group_seconds'; groupFields[newFieldName] = interval; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } item[this_1.fieldKeys[newFieldName]] = (isInRangeAvail ? undefined : new Date(newDate.setSeconds(date.getSeconds())).toString()); } break; } } } } else if (!isNaN(Number(item[this_1.fieldKeys[fieldName]])) && group.type === 'Number') { var isInRangeAvail = this_1.getRange(group, Number(item[this_1.fieldKeys[fieldName]])); item[this_1.fieldKeys[fieldName]] = isInRangeAvail ? undefined : item[this_1.fieldKeys[fieldName]]; } else if (item[this_1.fieldKeys[fieldName]] && group.type === 'Custom' && group.customGroups && group.customGroups.length > 0) { var newFieldName = fieldName + '_custom_group'; var customGroups = group.customGroups; var groupValue = void 0; this_1.groupingFieldsInfo[fieldName] = fieldName; this_1.groupingFieldsInfo[newFieldName] = fieldName; for (var i_2 = 0, len_2 = customGroups.length; i_2 < len_2; i_2++) { var cGroup = customGroups[i_2]; if (cGroup.items && cGroup.items.length > 1) { customGroupFieldName = newFieldName; this_1.fieldKeys[newFieldName] = this_1.dataSourceSettings.type === 'CSV' ? (this_1.fieldKeys[newFieldName] ? this_1.fieldKeys[newFieldName] : this_1.fields.length) : newFieldName; if (this_1.fields.indexOf(newFieldName) === -1) { this_1.fields.push(newFieldName); } var isDataMatch = PivotUtil.inArray(item[this_1.fieldKeys[fieldName]].toString(), cGroup.items) === -1 ? false : true; item[this_1.fieldKeys[newFieldName]] = (isDataMatch ? (cGroup.groupName && cGroup.groupName !== '') ? cGroup.groupName : this_1.localeObj.getConstant('group') + ' ' + i_2 : (groupValue && groupValue !== item[this_1.fieldKeys[fieldName]].toString()) ? groupValue : item[this_1.fieldKeys[fieldName]].toString()); groupValue = item[this_1.fieldKeys[newFieldName]]; } } } var keys = Object.keys(item); var isCompleteSet = []; for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; isCompleteSet.push((item[key]) ? true : false); } fieldkeySet = (((isCompleteSet.indexOf(false) === -1) && keys.length === Object.keys(data[0]).length) ? item : fieldkeySet); //this.fields = Object.keys(fieldkeySet); } if (group.type === 'Date') { var isDataSource = false; var axisFields = [this_1.dataSourceSettings.rows, this_1.dataSourceSettings.columns, this_1.dataSourceSettings.values, this_1.dataSourceSettings.filters]; var groupKeys = Object.keys(groupFields); var gCnt = Object.keys(groupKeys).length; var groupField = void 0; for (var _a = 0, axisFields_1 = axisFields; _a < axisFields_1.length; _a++) { var axis = axisFields_1[_a]; if (!isDataSource && axis) { var cnt = axis.length; var i_3 = 0; while (i_3 < cnt) { if (axis[i_3].name === fieldName) { isDataSource = true; var actualField = axis[i_3]; axis.splice(i_3, 1); var dataFields = this_1.dataSourceSettings.rows; dataFields = dataFields.concat(this_1.dataSourceSettings.columns, this_1.dataSourceSettings.values, this_1.dataSourceSettings.filters); while (gCnt--) { var caption_1 = actualField.caption ? actualField.caption : actualField.name; if (this_1.clonedReport) { var clonedFields = this_1.clonedReport.rows; clonedFields = clonedFields.concat(this_1.clonedReport.columns, this_1.clonedReport.values, this_1.clonedReport.filters); var cloneField = PivotUtil.getFieldByName(groupKeys[gCnt], clonedFields); if (cloneField) { caption_1 = cloneField.caption ? cloneField.caption : cloneField.name; } } if (!PivotUtil.getFieldByName(groupKeys[gCnt], dataFields)) { groupField = groupFields[groupKeys[gCnt]]; caption_1 = (caption_1.indexOf(' (') !== -1 && caption_1.indexOf(')') !== -1) ? caption_1.slice(caption_1.indexOf('(') + 1, caption_1.length - 1) : caption_1; var newField = { name: groupKeys[gCnt], caption: (this_1.localeObj ? this_1.localeObj.getConstant(groupField) : groupField) + ' (' + caption_1 + ')', type: 'Count', showNoDataItems: actualField.showNoDataItems, baseField: actualField.baseField, baseItem: actualField.baseItem, showFilterIcon: actualField.showFilterIcon, showSortIcon: actualField.showSortIcon, showEditIcon: actualField.showEditIcon, showRemoveIcon: actualField.showRemoveIcon, showSubTotals: actualField.showValueTypeIcon, allowDragAndDrop: actualField.allowDragAndDrop, expandAll: actualField.expandAll, groupName: actualField.groupName }; axis.splice(i_3, 0, newField); this_1.groupingFieldsInfo[newField.name] = fieldName; } else { this_1.groupingFieldsInfo[groupKeys[gCnt]] = fieldName; } } break; } else if (axis[i_3].name.indexOf(fieldName) > -1) { var axisField = groupFields[axis[i_3].name]; var currentField = axis.filter(function (axisField) { return axisField.name === fieldName; })[0]; if (!isNullOrUndefined(currentField)) { var currentFieldCaption = currentField.caption ? (currentField.caption.indexOf(' (') !== -1 && currentField.caption.indexOf(')') !== -1) ? currentField.caption.slice(currentField.caption.indexOf('(') + 1, currentField.caption.length - 1) : currentField.caption : fieldName; axis[i_3].caption = (this_1.localeObj ? this_1.localeObj.getConstant(axisField) : currentField) + ' (' + currentFieldCaption + ')'; } } i_3++; } if (isDataSource) { break; } } } gCnt = Object.keys(groupKeys).length; var field = this_1.getMappingField(fieldName, this_1.clonedReport ? this_1.clonedReport.fieldMapping : this_1.dataSourceSettings.fieldMapping); var caption_2 = field.caption ? field.caption : fieldName; while (gCnt--) { groupField = groupFields[groupKeys[gCnt]]; for (var i_4 = 0, len_3 = this_1.dataSourceSettings.formatSettings.length; i_4 < len_3; i_4++) { if (this_1.dataSourceSettings.formatSettings[i_4].name === groupKeys[gCnt]) { this_1.dataSourceSettings.formatSettings.splice(i_4, 1); break; } } if (groupField !== 'Quarters' && groupField !== 'QuarterYear') { var formatSettings = { name: groupKeys[gCnt], type: ['Years', 'Months', 'Days'].indexOf(groupField) > -1 ? 'date' : 'time', format: ((groupField === 'Years') ? 'yyyy' : (groupField === 'Months') ? 'MMM' : (groupField === 'Days') ? 'd-MMM' : (groupField === 'Hours') ? 'hh a' : (groupField === 'Minutes') ? ':mm' : (groupField === 'Seconds') ? ':ss' : undefined) }; this_1.dataSourceSettings.formatSettings.push(formatSettings); } if (!isDataSource) { var mappingField = this_1.getMappingField(groupKeys[gCnt], this_1.dataSourceSettings.fieldMapping); if (groupKeys[gCnt] !== fieldName && isNullOrUndefined(mappingField.name)) { var newField = { name: groupKeys[gCnt], caption: (this_1.localeObj ? this_1.localeObj.getConstant(groupField) : grou