Working with Table Headers

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example displays working with table headers. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Data Analysis section):

-(void)executeExample {
    // Get left table header
    SPPLPivotTableHeader leftPivotTableHeader = m_gridPivotTable->leftHeader();
    // Get table, to whcih header belongs
    SPPLPivotTable relatedTable = leftPivotTableHeader->relatedTable();
    printf("Number of table rows: %d \n", relatedTable->rowCount());
    /* Get left header of pivot object
    for building data tables */
    SPPLPivotHeader leftPivotHeader = m_gridPivot->leftHeader();
    // Create a new object of left table header
    SPPLPivotTableHeader customLeftPivotTableHeader =
    PPLPivotTableHeader::pivotTableHeader(relatedTable, leftPivotHeader);
    // Get array of all table header dimensions
    SNArray leftDimensions = customLeftPivotTableHeader->dimensions();
    if (leftDimensions->count() > 0) {
        printf("Table left header dimensions: \n");
        for (int i = 0; i < leftDimensions->count(); i++) {
            SPPLDimension dimension = leftDimensions->objectAtIndex<PPLDimension>(i);
            printf("%s \n", dimension->name()->UTF8String());
        }
        } else {
        printf("There are no dimensions in table left header \n");
    }
    printf("Number of left header elements: %d \n", customLeftPivotTableHeader->elements()->elementsCount());
    /* Get top header of pivot object
    for building data tables */
    SPPLPivotHeader topPivotHeader = m_gridPivot->topHeader();
    SPPLPivotTableHeader customTopPivotTableHeader = PPLPivotTableHeader::pivotTableHeader(relatedTable,  [self pivotStateForDimensions: (topPivotHeader->dimensions())], topPivotHeader, false);
    //SPPLPivotTableHeader customTopPivotTableHeader = PPLPivotTableHeader::pivotTableHeader(relatedTable, topPivotHeader);
    // Get array of all table header dimensions
    SNArray topDimensions = customTopPivotTableHeader->dimensions();
    if (topDimensions->count() > 0) {
        printf("Table top header dimensions: \n");
        for (int i = 0; i < topDimensions->count(); i++) {
            SPPLDimension dimension1 = topDimensions->objectAtIndex<PPLDimension>(i);
            printf("%s \n", dimension1->name()->UTF8String());
        }
        } else {
        printf("There are no table top header dimensions \n");
    }
    printf("Number of top header elements: %d", customTopPivotTableHeader->elements()->elementsCount());
}

// Returns table state settings for specified dimensions
-(SPPLPivotState) pivotStateForDimensions: (SNArray) dimensions {
    /* Determine state of pivot object
    for building data tables */
    SPPLPivotState pivotState = PPLPivotState::pivotState(m_gridPivot);
    SPPLDimensionSelectionSet selSet = new PPLDimensionSelectionSet();
    for (int i = 0; i < dimensions->count(); ++i) {
        SPPLDimension dimension = dimensions->objectAtIndex<PPLDimension>(i);
        SPPLDimensionSelection selection = new PPLDimensionSelection(dimension);
        selection->selectAll();
        
        selSet->addSelection(selection, dimension->id());
    }
    // Determine dimension selection set
    pivotState->setSelectionSet(selSet);
    return pivotState;
}

After executing the example the development environment console displays the number of table rows, dimension names, and the number of table left and top headers:

Number of table rows: 5

Table left header dimensions:

World

Number of left header elements: 4

Table top header dimensions:

Calendar

Number of top header elements: 6

See also:

Example of pplib++ Library Use