Adding Rows to a Grid


#1

Hi!

Is it possible to add a row to an existing grid?

I would have a grid of customer order lines in a grid and would like to add a new line.

Thanks!

Wg


#2

Yes it is! If you add new items to your data-source you must tell the data-grid to reload the data. If you take the GettingStarted example (this is in the Samples folder of the grids package), change the _data array to an NSMutabelArray - then add the following to the end of viewDidLoad:

- (void)viewDidLoad
{
    // ... original code goes here
    
    [self performSelector:@selector(addObjects) withObject:self afterDelay:1.0];
}

Then implement the addObjects method as follows:

-(void)addObjects{

    // add some new objects
    [_data addObjectsFromArray:[NSMutableArray arrayWithArray:[PersonDataSource generatePeople:2]]];

    // tell the grid to reload
    [_shinobiDataGrid reload];
    
    // repeat!
    [self performSelector:@selector(addObjects) withObject:self afterDelay:1.0];
}

You should see new items being added to the data-grid.

If you are using the SDataGridDataSourceHelper you need to inform it that your data has changed. It will then update its state (sorting, grouping), then inform the data-grid.

[_datasourceHelper reloadData];

#3

Thanks!

I was looking more along the lines of adding a line from inside the grid but I saw the demo app which showed it.

Wg


#4

Which demo app?


#5

Just for closure in case someone else comes looking; the app was their demo app which was available at the time showcasing the controls. Not sure if it’s still in the app store but the source is not available.

Wg