Working with Table Data Source

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes some methods of working with table data source. After starting the example the following operations are executed:

Required Files

It is required to add the following file to the base example Displaying of Express Report:

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Express Report section):

// Get array of data view controllers
NSArray *controllers =[m_controller dataViewControllers];
// Parse data view controllers in cycle
for(NSObject *controller in controllers)
{
    // Check if the current controller is a table view controller
    if([controller isMemberOfClass:[MAGridDataViewController class]])
    {
        // Get table view controller object
        MAGridDataViewController *gridController = (MAGridDataViewController *)controller;
        // Get table data source
        GridDataViewDatasource *grid = [gridController gridDatasource];
        // Get pivot object for building data tables
        SPPLPivot pivot = [grid pivot];
        // Get pivot object data source for building data tables
        SPPLDataSource datasource = pivot->dataSource();
        // Get array of data source dimensions
        SNArray dimensions = datasource->dimensions();
        // Display data source dimension names in the development environment console
        NSLog(@"Dimensions contained in pivot object data source for building data tables:");
        for(int i = 0; i < dimensions->count(); i++)
        {
            SPPLDimension dimension = dimensions->objectAtIndex<PPLDimension>(i);
            NSLog(@"%@", dimension->name()->nsString());
        }
        // Get data table
        SPPLPivotTable pivotTable = [grid pivotTable];
        // Check if table data source is empty
        if([grid isEmpty] == NO)
        {
            // Get controller view
            UIView *view = [gridController view];
            // Get array of subviews
            NSArray *subviews = [view subviews];
            // Parse subviews in cycle
            for(NSObject *subview in subviews)
            {
                // Check if the current view is a table view
                if([subview isMemberOfClass:[NuGridView class]])
                {
                    // Get table view object
                    NuGridView *gView = (NuGridView *)subview;
                    // Check if table contains required number of columns
                    if(pivotTable->columnCount() > 1)
                    {
                        // Get access and display in the development environment console indent of column header with the 1 index
                        NSInteger indentForHeader = [grid gridView:gView indentForHeaderForColumn:1 number:0];
                        NSLog(@"Indent of column header with the 1 index: %i", indentForHeader);
                        // Get column persisted key
                        MAGridDataSourcePersistentKey *columnPersistentKey = [grid columnPersistentKeyByNumber:1];
                        // Get parent column persisted key
                        MAGridDataSourcePersistentKey *parentColumn = [grid parentColumnOfColumn:columnPersistentKey];
                        // Check result of getting parent column
                        if(parentColumn != nil)
                        {
                            // Display the number of parent column obtained by its persisted key in the development environment console
                            NSLog(@"Parent column number for the column 1: %i", [grid columnNumberByPersistentKey: parentColumn]);
                        }
                        else
                        {
                            NSLog(@"Parent column for the column %d is missing", [grid columnNumberByPersistentKey:columnPersistentKey]);
                        }
                    }
                    else
                    {
                        NSLog(@"Failed to get column");
                    }
                    // Check if table contains required number of rows
                    if(pivotTable->rowCount() > 1)
                    {
                        // Get acces and display in the development environment console indent of column header with the 1 index
                        NSInteger indentForHeader = [grid gridView:gView indentForHeaderForRow:1 number:0];
                        NSLog(@"Indent of column header with the 1 index: %i", indentForHeader);
                        // Get row persisted key
                        MAGridDataSourcePersistentKey *rowPersistentKey = [grid rowPersistentKeyByNumber:1];
                        // Get parent row persisted key
                        MAGridDataSourcePersistentKey *parentRow = [grid parentRowOfRow:rowPersistentKey];
                        // Check result of getting parent row
                        if(parentRow != nil)
                        {
                            // Display the number of parent row obtained by its persisted key in the development environment console
                            NSLog(@"Parent row number for the row 1: %i", [grid rowNumberByPersistentKey: parentRow]);
                        }
                        else
                        {
                            NSLog(@"Parent row for the row %d is missing", [grid rowNumberByPersistentKey:rowPersistentKey]);
                        }
                    }
                    else
                    {
                        NSLog(@"Failed to get row");
                    }
                    break;
                }
            }
            // Get persisted key for sparkline column
            MAGridDataSourcePersistentKey *sparklineColumnKey = [grid sparklineColumnPersistentKey];
            // Display persisted key description for sparkline column in the development environment console
            NSLog(@"Persisted key description for sparkline column: %@",[sparklineColumnKey description]);
        }
        // Update table data source
        [grid updateAsync];
        break;
    }
}

It is also required to replace the code in the static example file MAExpressAnalysisReportViewControllerDelegateImpl.mm in the initWithOlapReport: method in the block:

if (self.isGridEnabled)

with the following code:

// Get report settings
SNDictionary gridOlapPlist = m_olapReport->storageDictionary()->objectForKey<NDictionary>(GRID_OLAP_KEY);
// Create a report
SPPLOlapReport gridOlapReport = NULL;
if (gridOlapPlist != NULL) {
    gridOlapReport = PPLOlapReport::olapReport(m_olapReport->descriptor(), gridOlapPlist);
}
// Create a pivot object for building data table
m_gridPivot = (gridOlapReport != NULL) ? PPLPivot::pivot(gridOlapReport) : PPLPivot::pivot(m_olapReport);
// Create a data table
m_gridPivotTable = PPLPivotTable::pivotTable(m_gridPivot);
// Get data table settings
SNDictionary gridPivotTablePlist = m_olapReport->storageDictionary()->objectForKey<NDictionary>(GRID_PIVOT_TABLE_KEY);
// Check if table settings object is empty
if (gridPivotTablePlist != NULL)
{
    // Set table settings
    m_gridPivotTable->setupFromPlist(gridPivotTablePlist);
}
else
{
    // Apply table settings
    [self applyGridSettings];
}
// Create a data source based on data table
m_gridDatasource = [[GridDataViewDatasource alloc] initWithPivotTable:m_gridPivotTable];

After executing the example the development environment console displays information obtained from table data source, and also the list of dimensions contained in the pivot object for building data tables:

Dimensions contained in the pivot object data source for building data tables:

Calendar

World

Indicators

Indent of column header with the index 1: 0

Parent column for the column 1 is missing

Indent of row header with the index 1: 1

Parent row number for the row 1:  0

Persisted key description for sparkline column: <MAGridDataSourcePersistentKey=nil>

 

Then it is required to create the table data source delegate class that implements handling of table events, to add class header file to source code of the ViewController class, and also to place in the body of the executeExample method after the block

if([grid isEmpty] == NO)

the following code:

// Create an observer object of table data source events
DataViewDatasourceExample *exampleDelegate = [[DataViewDatasourceExample alloc] initWithName: @"gridDatasource"];
// Subscribe observer object for data source events
[grid addEventObserver:exampleDelegate];
// Call data update event
[grid pivotTableUpdated];

After executing the updated example the development environment console displays an additional message about the called table data update event:

gridDatasource: Data update event, event code: 1

See also:

Example of Component Use