Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example displays working with table header total elements. After starting the example the following operations are executed:
Table top header and its elements are returned.
Calculated series settings are created and deleted.
A new element is created and checked if it is calculated.
A new total element is created and checked if it belongs to top header.
It is determined, which top header elements are total elements.
The tree of elements for the first table header dimension is returned, the number of element is calculated, and the first root node of this tree is determined.
Descriptions of table header elements sorted by ascending are displayed in the development environment console.
Table header total element is an element corresponding to the cell at the intersection of header column and the row containing totals, and vice versa.
It is required to add the following file to the Data Analysis basic example:
SortElementsManager.h. Class for sorting table element tree nodes.
Executing the example requires to create a class containing a method for sorting table element tree nodes, and also to add a class header file into the source code of the ViewController class (see the Data Analysis section). Then it is required to place the following code in the body of the executeExample method of the ViewController class:
-(void)executeExample { // Get table top header SPPLPivotTableHeader topPivotHeader = m_gridPivotTable->topHeader(); // Display information about calculated header element [self printCalculatedElementInfo: topPivotHeader->elements() forHeaderElementWithIndex: 0]; // Display information about header total element [self printTotalsElementsInfo: topPivotHeader->elements()]; if (topPivotHeader->dimensions() > 0) { // Display information about element tree nodes for dimension with specified index [self printTreeNodesInfo: topPivotHeader ForDimensionWithIndex: 0]; // Display descriptions of header elements sorted by descending [self printSortedHeaderElementsDescriptions: topPivotHeader->elements()]; } } // Displays information about header calculated elements -(void)printCalculatedElementInfo: (SPPLPivotTableHeaderElements) pivotHeaderElements forHeaderElementWithIndex: (int) elemIndex { if (pivotHeaderElements->elementsCount() > 0) { // Get table header element by index SPPLPivotTableHeaderElement parentElement = pivotHeaderElements->getElementByIndex(elemIndex); SPPLPivotTableCalculatorSetting calculatorSetting = new PPLPivotTableCalculatorSetting(); // Create a calculated element based on obtained table header element SPPLPivotTableHeaderElement calculatedElement = pivotHeaderElements->createCalculatedElement(parentElement, [self getCalculatorSetting]); // Check if element is calculated if (pivotHeaderElements->isElementCalculated(calculatedElement)) { printf("Element with the %d index is calculated\n", pivotHeaderElements->getIndexOfElement(calculatedElement)); } else { printf("New element is not calculated\n"); } } } // Returns calculated element settings -(SPPLPivotTableCalculatorSetting)getCalculatorSetting { // Create a container of data table calculated series settings SPPLPivotTableCalculatorSettings calculatorSettings = new PPLPivotTableCalculatorSettings(); // Add new settings calculatorSettings->addSetting(new PPLPivotTableCalculatorSetting()); calculatorSettings->addSetting(new PPLPivotTableCalculatorSetting()); calculatorSettings->addSetting(new PPLPivotTableCalculatorSetting()); printf("Initial number of calculated series settings: %d\n", calculatorSettings->settingsCount()); // Keep only last setting for (int i = 0; i < calculatorSettings->settingsCount(); i++) { calculatorSettings->removeSetting(calculatorSettings->setting(i)); } printf("Obtained number of calculated series settings: %d\n", calculatorSettings->settingsCount()); if (calculatorSettings->settingsCount() > 0) { return calculatorSettings->setting(0); } else { return NULL; } } // Call infomation about header total element -(void)printTotalsElementsInfo: (SPPLPivotTableHeaderElements) pivotHeaderElements { // Get all dimensions SNArray dimensions = [self allDimensions]; // Create a new total element SPPLPivotTableHeaderElement totalsElement = pivotHeaderElements->createTotalsElement(dimensions, NULL, PPLPivotTableTotalsTypes::kSum); // Check if created element belongs to current header if (pivotHeaderElements->checkMembership(totalsElement)) { int currentIndex = pivotHeaderElements->getIndexOfElement(totalsElement); printf("Total element belongs to top header and has the %d index \n", currentIndex); } else { printf("New total element does not belong to current header \n"); } for (int i = 0; i < pivotHeaderElements->elementsCount(); i++) { SPPLPivotTableHeaderElement element = pivotHeaderElements->getElementByIndex(i); // Check if header element is total element if (pivotHeaderElements->isElementInTotals(element)) { printf("Header element with the %d index is total element \n", i); } } } // Displays information about element tree nodes for dimension with specified index -(void)printTreeNodesInfo: (SPPLPivotTableHeader) pivotTableHeader ForDimensionWithIndex: (int) dimIndex { // Get first dimension of table header SPPLDimension dimension = pivotTableHeader->dimensions()->objectAtIndex<PPLDimension>(dimIndex); // Get tree of selected header elements for this dimension SPPLCommonTree tree = pivotTableHeader->elements()->getSelectedElementsTreeForDimension(dimension); printf("Number of nodes in element tree for the %s dimension: %d \n", dimension->name()->UTF8String(), tree->count()); if (tree->count() > 0) { SPPLCommonTreeNode rootNode = tree->rootNodes()->objectAtIndex<PPLCommonTreeNode>(0); printf("First tree root node: %s \n", rootNode->description()->UTF8String()); } } // Displays descriptions of header elements sorted by descending -(void)printSortedHeaderElementsDescriptions: (SPPLPivotTableHeaderElements) pivotHeaderElements { if (pivotHeaderElements->elementsCount() > 0) { // Sort header elements SortElementsManager *sort = new SortElementsManager(); SNArraySortSelector sortSelector = new NSpecificSelectorMethod2Returns<SortElementsManager, NID, NID, NComparisonResult>(sort, &SortElementsManager::sortSelector); pivotHeaderElements->sortElementsUsingSelector(sortSelector); // Display tree nodes in the development environment console printf("Descriptions of header elements sorted by descending:\n"); for (int i = 0; i < pivotHeaderElements->elementsCount(); i++) { printf("%s \n", pivotHeaderElements->getElementByIndex(i)->description()->UTF8String()); } } }
After executing the example the development environment console displays indexes of all calculated elements and total elements of table top header, the number of nodes in element tree for the first header dimension, description of the first root node and description of header elements sorted by descending:
Initial number of calculated series settings: 3
Obtained number of calculated series settings: 1
element with the 1 index is calculated
Total element belongs to top header and has the 7 index
Header element with the 7 index is total element
Number of nodes in element tree for the Time dimension: 7
First tree root node: 2006 ,(8, parent: 0)
Descriptions of header elements sorted by descending:
PPLDataSourceMatrixKeyBase parts=1 (16033=>14 )
PPLDataSourceMatrixKeyBase parts=1 (16033=>13 )
PPLDataSourceMatrixKeyBase parts=1 (16033=>11 )
PPLDataSourceMatrixKeyBase parts=1 (120448481=>4294967295 )
PPLDataSourceMatrixKeyBase parts=1 (16033=>12 )
PPLDataSourceMatrixKeyBase parts=1 (16033=>10 )
PPLDataSourceMatrixKeyBase parts=1 (16033=>8 )
PPLDataSourceMatrixKeyBase parts=1 (16033=>9 )
See also: