Creating ShinobiGrid with Formula


#1

I’m newbie with ShinobiControls and i bought the frarmework for grid and chart, i would like to know how can i set a formula to a particular column and row in my shinobigrid. 


#2

Greetings Program!

What I have done in the past is calculate the formula in the prepareCellForDisplay method:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell
{
	int row = cell.coordinate.row.rowIndex;
	
    // locate the line that is rendered on this row
    ServiceOrderLine *orderLine = self.serviceOrderLines[row];
	
	// Column type
	SDataGridTextCell *gridCell = (SDataGridTextCell *)cell;
	gridCell.textField.text = @"";
	
	if ([cell.coordinate.column.title isEqualToString:@"Qty"] && ![orderLine.orderQuantity isNullOrEmpty])
	{
		gridCell.textField.text = [orderLine.orderQuantity decimalString];
		
		// select numeric input for this column
		gridCell.textField.keyboardType = UIKeyboardTypeNumberPad;
	}
	else if ([cell.coordinate.column.title isEqualToString:@"Unit Price"] && ![orderLine.unitPrice isNullOrEmpty])
	{
		gridCell.textField.text = [orderLine.unitPrice currencyString];
	}
	else if ([cell.coordinate.column.title isEqualToString:@"Ext. Price"] && ![orderLine.extendedPrice isNullOrEmpty])
	{
		gridCell.textField.text = [(orderLine.orderQuantity * orderLine.unitPrice) currencyString];
	}
}

Wg


#3

Thank you for the reply apology if i will ask this but what header file should i use? it display an error expected a type. thank you again


#4

This should just need #import <ShinobiGrids/ShinobiDataGrid.h>


#5

i don’t see this <ShinobiGrids/ShinobiDataGrid.h>  am i missing something? 


#6

You’ll need to make sure you’ve added the ShinobiGrids.framework.

Wg


#7

ShinobiDataGrid was added in the 2.0 release. You will need to upgrade to the latest version to use it. 


#8

Sorry about that; I just assumed it was the DataGrid :blush:.

I haven’t tested this but based on how the ShinobiGrid SimpleGrid sample app works, you could perhaps do the following in the cellForGridCoord:

- (SGridCell *)shinobiGrid:(ShinobiGrid *)grid cellForGridCoord:(const SGridCoord *) gridCoord
{
	SGridAutoCell *cell;
    
	// Create cell code here.
	
    // locate the line that is rendered on this row
    int row = gridCoord.row.index - 1;
    ServiceOrderLine *orderLine = self.serviceOrderLines[row];

    //Populate the first row with title for each column, and apply the header style
    if([gridCoord hasRow:SGridRowZero])
    {        
        // Header cell code here.
    }
    else {
        if (gridCoord.column == 0) {
            cell.textField.text = [orderLine.orderQuantity decimalString];
        }
        else if (gridCoord.column == 1) {
            cell.textField.text = [orderLine.unitPrice currencyString];
        }
        else if (gridCoord.column == 2) {
            cell.textField.text = [(orderLine.orderQuantity * orderLine.unitPrice) currencyString];
        }
    }
}

Wg


#9

please ignore this message i just cant delete it from here, i fixed my issue by deleting the path of old framework version. 


#10

What i understood with your solution is the ServiceOnline is  the source of data to be computed, what if i will just type any figures in column B and C then compute the sum in Column D for whatver the value is typed in B and C.

thank you again for your patience and time.


#11

You’ll still need to use a datasource to store the modified values. Here’s a stripped down version of what I do:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid didFinishEditingCellAtCoordinate:(SDataGridCoord *)coordinate
{
    // Find the cell that was edited.
    SDataGridTextCell *cell = (SDataGridTextCell*)[shinobiDataGrid visibleCellAtCoordinate:coordinate];
	
    // Locate the object index for this row.
    int row = coordinate.row.rowIndex;
	
    // Locate the line that is rendered on this row.
    ServiceOrderLine *orderLine = [self.serviceOrderLines objectAtIndex:row];
    
    if ([cell.coordinate.column.title isEqualToString:@"Qty"])
    {
		orderLine.orderQuantity = [cell.textField.text decimalValue];
    }
    if ([cell.coordinate.column.title isEqualToString:@"Unit Price"])
    {
		orderLine.unitPrice = [cell.textField.text decimalValue];
    }
		
	// Update the service order line.
	[self.serviceOrderLines replaceObjectAtIndex:row withObject:orderLine];

	// Reload the data grid (which will recalculate the extended price).
	[shinobiDataGrid reload];
}

Wg