Executing Transactions for Changing Table Proxy Data Source Settings

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes executing of transactions for changing table proxy data source settings. 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 create a class used to get messages about table proxy data source and also to add a class header file into source code of the ViewController class (see the Displaying of Express Report section). The data source table should contain cells with expanders by indexes specified in the code of the executeExample method (code fragment, which is filled with values of the array for storing table collapsed expander coordinates). The it is required to place the following code in the body of the executeExample method of the ViewController class:

// Get data view array
NSArray *controllers =[m_controller dataViewControllers];
// Parse data view controllers in cycle
for(NSObject *controller in controllers)
{
    // Check if the current data view is a table data view
    if([controller isMemberOfClass:[MAGridDataViewController class]])
    {
        // Get table data view controller object
        MAGridDataViewController *gridController = (MAGridDataViewController *)controller;
        // Get table data 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;
                // Get table delegate object
                MAGridDelegate *gridDelegate = (MAGridDelegate *)[gView gridDelegate];
                // Get table proxy data source
                MAGridProxyDataSource *proxyDatasource =[gridDelegate proxyDataSource];
                // Set table data view scale in proxy data source
                [proxyDatasource setGridViewZoomScale: [NSNumber numberWithFloat:0.5]];
                // Call internal table data view method that sets table data view scale
                [gridController performSelector:@selector(setupGridViewZoom) withObject:nil];
                // Get and display maximum cell width from proxy data source in the development environment console
                int maxCellWidth = [proxyDatasource maxCellWidth];
                NSLog(@"Maximum cell width in proxy data source: %d", maxCellWidth);
                // Execute automatic selection of table cell size
                [proxyDatasource adaptCellsSizeInGridView:gView forWidth:60];
                // Call internal table data view method that updates maximum cell width from proxy data source
                [gridController performSelector:@selector(updateColumnMaxWidth) withObject:nil];
                // Get and display maximum cell width from proxy data source after value update in the development environment console
                maxCellWidth = [proxyDatasource maxCellWidth];
                NSLog(@"Maximum cell width in proxy data source after value update: %d", maxCellWidth);
                // Create an array for storing table collapsed expander coordinates
                NSMutableArray *expanders = [[NSMutableArray alloc] init];
                // Fill array for storing table collapsed expander coordinates with values
                MAGridDataViewControllerExpanderInfo *exp = [MAGridDataViewControllerExpanderInfo new];
                exp.left = 0;
                exp.top = 191;
                [expanders addObject:exp];
                MAGridDataViewControllerExpanderInfo *exp1 = [MAGridDataViewControllerExpanderInfo new];
                exp1.left = 0;
                exp1.top = 165;
                [expanders addObject:exp1];
                MAGridDataViewControllerExpanderInfo *exp2 = [MAGridDataViewControllerExpanderInfo new];
                exp2.left = 0;
                exp2.top = 119;
                [expanders addObject:exp2];
                MAGridDataViewControllerExpanderInfo *exp3 = [MAGridDataViewControllerExpanderInfo new];
                exp3.left = 0;
                exp3.top = 64;
                [expanders addObject:exp3];
                MAGridDataViewControllerExpanderInfo *exp4 = [MAGridDataViewControllerExpanderInfo new];
                exp4.left = 0;
                exp4.top = 9;
                [expanders addObject:exp4];
                // Set array of table collapsed expanders in proxy data source
                [proxyDatasource setCollapsedExpandersAtStartup:expanders];
                // Get number of data proxy source table rows
                int rowCount = [proxyDatasource gridViewRowCount:gView];
                // Collapse table expanders specified in array of proxy data source collapsed expanders
                for(MAGridDataViewControllerExpanderInfo *expander in [proxyDatasource collapsedExpandersAtStartup]) {
                    // Check row existence by index
                    if(expander.top < rowCount) {
                        // Get table row by specified coordinates
                        NuGridCell *cell = [proxyDatasource gridView:gView cellInRow:expander.top inColumn:expander.left];
                        // Check if obtained cell contains expander
                        if([cell isMemberOfClass: [NuGridExpandableCell class]]) {
                            // Collapse obtained cell expander
                            [proxyDatasource gridView:gView collapseRow: expander.top];
                        }
                    }
                }
                // Create an observer object of table proxy data source events
                gridUpdateObserver *observer = [[gridUpdateObserver alloc] initWithName:@"Observer 1"];
                // Subscribe observer object for proxy data source events
                [proxyDatasource addObserver:observer];
                // Start transaction for changing proxy data source settings
                [proxyDatasource beginSettingTransaction];
                // Save table proxy data source state
                NSData *state = [proxyDatasource saveState];
                // Finish transaction for changing proxy data source settings
                [proxyDatasource endSettingTransaction];
            }
        }
    }
}

 After executing the example the mobile device screen displays the express report containing the table, which scale is changed, automatic cell size selection is executed, and also the specified expanders are collapsed:

Besides, the development environment console displays information about table proxy data source, and also messages about handling of the observer object events occurred due to the transaction for changing proxy data source settings with sending notifications:

Maximum cell width in proxy data source: 400

Maximum cell width in proxy data source after value update: 148

Operations of the Observer 1 object executed before updating proxy data source with the dataSource key

Operations of the Observer 1 object executed after updating proxy data source with the dataSource key

 

Then it is required to replace the code strings in the example

// Start transaction for changing proxy data source settings
[proxyDatasource beginSettingTransaction];
// Save table proxy data source state
NSData *state = [proxyDatasource saveState];
// Finish transaction for changing proxy data source settings
[proxyDatasource endSettingTransaction];

 with the following code:

// Remove territory dimension data in the second table row
[proxyDatasource gridView:gView removeRow:1 headerLevel:0];
// Remove calendar dimension data in the second table column
[proxyDatasource gridView:gView removeColumn:1 headerLevel:0];
// Start transaction for changing prxy data source settings without sending notifications
[proxyDatasource beginSilentSettingTransaction];
// Call the method that executes operations required before uodating proxy data source, for all observers of proxy data source
[proxyDatasource beforeUpdate:@"beginSilentSettingTransaction"];
// Save table proxy data source state
NSData *state = [proxyDatasource saveState];
// Finish transaction for changing proxy data source without sending notifications
[proxyDatasource endSilentSettingTransaction];
// Repeat calling of the method that executes operations required before updating proxy data source, for all observers of proxy data source
[proxyDatasource beforeUpdate:@"endSilentSettingTransaction"];

After executing the updated example the mobile device screen displays the express report containing the table, in which the specified rows and columns are removed:

The development environment console also displays additional message about executing in the observer object operations required before updating proxy data source:

Operations of the Observer 1 object executed before updating proxy data source with the endSilentSettingTransaction key

 

This event was called with the endSilentSettingTransaction key after finishing the transaction for changing proxy data source settings without sending notifications. The identical event with the beginSilentSettingTransaction key did not occur because it was called in the program during the transaction execution.

The array of collapsed table expanders in proxy data source can also be set by means of table data view, to do this, replace the strings:

// Set array of collapsed table expanders in proxy data source
[proxyDatasource setCollapsedExpandersAtStartup:expanders];

with the following code:

// Set array of collapsed table expanders in view controller
[gridController setCollapsedExpandersAtStartup:expanders];

See also:

Example of Component Use