Simple shinobiDataGrid formatting of cells


#1

I have a simple shinobiDataGrid that requires a simple formatting like a wordwrap or textalingment, maybe a cell padding it there is.

Where can i get a good example of simple shinobiDataGrid formatting.

my grid 

i tried experementing plase see below a part of my code but it seems i cannot get the simple style to work.

_shinobiDataGrid=[[ShinobiDataGridalloc]initWithFrame:CGRectMake(8, 5, 682, 295)];

    _shinobiDataGrid.canReorderRows=NO;

    [self.viewArrivaladdSubview:_shinobiDataGrid];

    

    _shinobiDataGrid.defaultCellStyleForHeaderRow.textColor=[UIColorblackColor];

    _shinobiDataGrid.defaultGridLineStyle.width=1.f;

    _shinobiDataGrid.defaultGridLineStyle.color=[UIColorcolorWithWhite:0.3falpha:1.f];

    _shinobiDataGrid.defaultRowHeight=@(35);

    

    _shinobiDataGrid.defaultCellStyleForHeaderRow.font=[UIFontfontWithName:@"Helvetica-Bold"size:15.f];

    _shinobiDataGrid.defaultCellStyleForHeaderRow.textAlignment=UITextAlignmentLeft;

  

    

    _shinobiDataGrid.layer.cornerRadius=10.f;

    

    SDataGridColumn *groupColumn=[[SDataGridColumnalloc]initWithTitle:@“Group”];

    groupColumn.width=@180;

    groupColumn.cellStyle.font=[UIFont fontWithName:@“Helvetica” size:13.f];

    groupColumn.cellStyle.textAlignment=UITextAlignmentLeft;

    groupColumn.headerCellStyle.textAlignment=UITextAlignmentLeft;

    

    [_shinobiDataGrid addColumn:groupColumn];

    

    SDataGridColumn *lineItems=[[SDataGridColumnalloc]initWithTitle:@“Line Items”];

    lineItems.width=@70;

    [_shinobiDataGrid addColumn:lineItems];

    

    SDataGridColumn *totalUnits=[[SDataGridColumnalloc]initWithTitle:@“Total Units”];

    totalUnits.width=@100;

    [_shinobiDataGrid addColumn:totalUnits];


#2

Greetings Program!

Here is how I do it:

- (void)addGrid
{
	if (shinobiDataGrid.columns.count > 0) return;
	
	shinobiDataGrid = [[ShinobiDataGrid alloc] initWithFrame:self.view.bounds];
	
	// Set the default font size.
	UIFont *font = [UIFont fontWithName:@"Helvetica" size:16.0f];
	
	// Set the padding for the cell.
	UIEdgeInsets padding = UIEdgeInsetsMake(5, 5, 5, 5);
	
    // Create an alternating row style.
    SDataGridCellStyle* alternatingRowStyle = [[SDataGridCellStyle alloc] init];
	alternatingRowStyle.font = font;
	alternatingRowStyle.contentInset = padding;
    alternatingRowStyle.backgroundColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
	
	// Create the selected row style.
	SDataGridCellStyle* selectedRowStyle = [[SDataGridCellStyle alloc] init];
    selectedRowStyle.font = font;
    selectedRowStyle.contentInset = padding;
	selectedRowStyle.backgroundColor = [UIColor yellowColor];
	selectedRowStyle.textColor = [UIColor blackColor];
	
	// Create the header style.
    // Style the headers to have a dark background, and white text.
	SDataGridCellStyle* headerStyle = [[SDataGridCellStyle alloc] init];
    headerStyle.font = font;
    headerStyle.contentInset = padding;
	headerStyle.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
	headerStyle.textColor = [UIColor whiteColor];
	
	// Set the row heights.
	shinobiDataGrid.defaultHeaderRowHeight = @30;
	shinobiDataGrid.defaultRowHeight = @30;
	
	// Set the cell styles.
    shinobiDataGrid.defaultCellStyleForHeaderRow = headerStyle;
	shinobiDataGrid.defaultCellStyleForSelectedRows = selectedRowStyle;
    shinobiDataGrid.defaultCellStyleForAlternateRows = alternatingRowStyle;
	
	// Create the style for the cell.
	SDataGridCellStyle* cellStyle;
	
	// Create the columns.
	SDataGridColumn* column;
	
	// *************************************
	// Qty column
	// *************************************
	column = [[SDataGridColumn alloc] initWithTitle:@"Qty"];
	column.editable = NO;
	column.width = @75;
	column.headerCellStyle.contentInset = padding;
	column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
	
	cellStyle = [[SDataGridCellStyle alloc] init];
    cellStyle.font = font;
    cellStyle.contentInset = padding;
	cellStyle.textAlignment = NSTextAlignmentCenter;
	column.cellStyle = cellStyle;
    [shinobiDataGrid addColumn:column];
	
	// *************************************
	// Uom column
	// *************************************
	column = [[SDataGridColumn alloc] initWithTitle:@"Uom"];
	column.editable = NO;
	column.width = @80;
	column.headerCellStyle.contentInset = padding;
	column.headerCellStyle.textAlignment = NSTextAlignmentLeft;
	
	cellStyle = [[SDataGridCellStyle alloc] init];
    cellStyle.font = font;
    cellStyle.contentInset = padding;
	cellStyle.textAlignment = NSTextAlignmentLeft;
	column.cellStyle = cellStyle;
    [shinobiDataGrid addColumn:column];
	
	// *************************************
	// And more columns
	// *************************************
	
    // Allow row selection.
    shinobiDataGrid.singleTapEventMask = SDataGridEventSelect;
    // Enable editing on double-tap.
    shinobiDataGrid.doubleTapEventMask = SDataGridEventEdit;
	
	// Set the data-source, delegate and resizing mask for the grid.
    shinobiDataGrid.dataSource = self;
	shinobiDataGrid.delegate = self;
	//shinobiDataGrid.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
	
	// add to the view
    [self.view addSubview:shinobiDataGrid];
}

Wg


#3

Nice. thank you .

:laughing:


#4

@Wizgod how can i add button inside the cell? i tried the code below where cell content is a UIView but it didnt work.

thank you again.

 UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

        button.frame = CGRectMake((cellContent.frame.size.width / 2) - 40, 35, 80, 30);

        [button setTitle:@"Button"forState:UIControlStateNormal];

        button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

        

        [cellContent addSubview:button];

        [textCell addSubview:cellContent];


#5

The cell frame has a width of 0 so the calculation for the origin.x won’t work.

Try this:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell
{
	// Column type
	SDataGridTextCell *gridCell = (SDataGridTextCell *)cell;

       // Clear the cell first before we set the text (in case this is a reused cell).
	gridCell.textField.text = @"";

	// Remove the button from the cell if it's not our column (reused cell).
	UIButton *button = (UIButton *)[cell viewWithTag:99];
	if (![cell.coordinate.column.title isEqualToString:@"Action"] && button != nil) [button removeFromSuperview];

	if ([cell.coordinate.column.title isEqualToString:@"Action"])
    {
                // Add the button if it doesn't exist in the cell.
		if (button == nil)
		{
			button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
			button.tag = 99;
			button.frame = CGRectMake(0, 0, 70, 30);
			[button setTitle:@"Button" forState:UIControlStateNormal];
			[button setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
			[button addTarget:self action:@selector(didTapActionButton:) forControlEvents:UIControlEventTouchUpInside];
		}
    }

Wg


#6

How can call i view controller when i click a particular cell im using storyboard


#7

If it’s not a popover then:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid didTapCellAtCoordinate:(SDataGridCoord *)coordinate isDoubleTap:(BOOL)isDoubleTap
{
    if ([cell.coordinate.column.title isEqualToString:@"Part/Service"])
    {
	SDataGridRow *row = cell.coordinate.row;
	
	NSLog(@"\n----------------------------------\nRow: %@\nCell: %@\n----------------------------------\n", row, cell);
	
	// The view controller you want to present from the storyboard.
	UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
	PrintViewController *printViewController = [storyBoard instantiateViewControllerWithIdentifier:@"PrintViewController"];
	
	// Set properties in view controller.
	printViewController.serviceOrder = self.serviceOrder;
		
	[self presentViewController:printViewController animated:YES completion:nil];
    }
}

Wg


#8

I have created a simple custom SDataGridCell (with a label inside). I would like to change a my label text color when I select some row, how can i do this? there are no method to detect from cell that her row was selected :sweat: .  Thanks in advance