How to add summary from the grid


#1

i have 3 columns that needs a summary at the last row, is there a way for me to add extra row for the summary?

thank you.


#2

Hi Ariel,

The grid won’t do this for you currently - you’ll just have to add an extra row and populate it manually :slight_smile:

Hope this helps

Rob


#3

thank you Rob, can you show me how to add additional row manually i though [array count]+1 will do in number of rows function but no luck below is part of my code.

  • (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell

{

    // both columns use a SDataGridTextCell, so we are safe to perform this cast

    SDataGridTextCell* textCell = (SDataGridTextCell*)cell;

    

    // locate the stock

    DelEquipment *delequipment=_sortedData[cell.coordinate.row.rowIndex];

    

    if ([cell.coordinate.column.titleisEqualToString:@“Equipment Name”]) {

        textCell.textField.text=delequipment.EquipmentName;

        

    }

    if ([cell.coordinate.column.titleisEqualToString:@“Drop Off”]) {

        textCell.textField.text=delequipment.DropOffs;

         textCell.textField.keyboardType=UIKeyboardTypeNumberPad;

    }

    if ([cell.coordinate.column.titleisEqualToString:@“Pick Up”]) {

        textCell.textField.text=delequipment.PickUp;

         textCell.textField.keyboardType=UIKeyboardTypeNumberPad;

    }

    if ([cell.coordinate.column.titleisEqualToString:@“Net”]) {

        textCell.textField.text=delequipment.Net;

    }

}


#4

Greetings Program!

I haven’t tested it but try this:

* I edited it to remove the calculation from the prepareCellForDisplay method and just set the delequipment properties in the addSummaryLine method so you don’t have to make any changes to the prepareCellForDisplay.

@implementation DelEquipmentViewController
{
        // Add this property to hold the object index of the summary line.
	int summaryLineIndex;
}


- (void)addSummaryLine
{
	if (_sortedData == nil)
	{
		NSLog(@"No data to summarize.");
		return;
	}

	if (summaryLineIndex != nil)
	{
		NSLog(@"Summary line already exists in datasource.");
		return;
	}
	
	NSLog(@"Adding summary line");

	double netTotal;
	for (int i = 0; i < _sortedData.count-1; i++) {
		netTotal = netTotal + [[[_sortedData objectAtIndex:i] valueForKey:@"Net"] decimalValue];
	}	

	DelEquipment *delequipment = [[DelEquipment alloc] init];
	delequipment.EquipmentName = @"SUMMARY";
	delequipment.DropOffs = @"";
	delequipment.PickUp = @"";		
        delequipment.Net = [NSString stringWithFormat:@"%f", netTotal];

	[_sortedData addObject:delequipment];
		
	// Store the summary index to track where it is just in case we start adding additional data lines
	// and need to remove the summary line and insert it back at the end.
	summaryLineIndex = _sortedData.count-1;
		
	// Reload the grid.
	[shinobiDataGrid reload];
}

Wg