Change the Padding on a Header and Cells of a Column or Row


#1

Greetings Programs!

How would I go about changing the padding on a (header) cell? Is there one for row as well?

Thanks!

Wg


ShinobiDataGrid: Column Header Padding
#2

Have a look at the properties available on SDataGridTextInputCell:

@interface SDataGridTextInputCell : SDataGridCell
@property (nonatomic, assign) float leftIndentForTextView;
@property (nonatomic, assign) float rightIndentForTextView;
@property (nonatomic, assign) float topIndentForTextView;
@property (nonatomic, assign) float bottomIndentForTextView;
@end

If you add these to a new header and import it, you should be able to set them on the header cell which should do the trick!


#3

Where would I set them? I’m using a SDataGridTextCell and my prepareCellForDisplay looks like this:

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

	int row = cell.coordinate.row.rowIndex;
	
    // locate the line that is rendered on this row
    NSArray *orderLine = serviceOrderLines[row];
    
	gridCell.textField.text = @"";
	
	if ([cell.coordinate.column.title isEqualToString:@"Line"] && ![Functions isNullOrEmpty:[orderLine valueForKey:@"LineNumber"]])
    {
        gridCell.textField.text = [[orderLine valueForKey:@"LineNumber"] stringValue];
    }
}

#4

Greetings Programs!

You should be able to set the indent as in the following code snippet.

The frame set is so that the cell will re-layout and re-apply the textview indent. We’re looking to address this in a future release :slight_smile:

- (void)didFinishLayingOutShinobiDataGrid:(ShinobiDataGrid *)grid
{
    for(SDataGridColumn *col in _grid.columns){
        SDataGridHeaderCell *hcell = col.headerCell;
        [hcell setLeftIndentForTextView:3];
        hcell.frame = hcell.frame;
    }
}

Hope this helps!
Rob


#5

I’m confused. I’m not seeing these indent properties in SDataGridTextInputCell.h. Would love to make use of them though…get rid of that unnecessary indent.


#6

rippling

Greetings Programs!

You should be able to set the indent as in the following code snippet.

The frame set is so that the cell will re-layout and re-apply the textview indent. We’re looking to address this in a future release :slight_smile:

Hope this helps!

Rob

Hi Rob!

Thanks for that but as kungfuters noted, the setLeftIndentForTextView property isn’t there. I get the xcode error: No Visible @interface for ‘SDataGridHeaderCell’ declares the selector ‘setLeftIndentForTextView’.

Perhaps I have an include missing?

Thanks!

Wg


#7

I tried setting the frame with a CGRectMake but that had an adverse effect on the display of the grid.

Wg


#8

Hi Wizgod.

As I mentioned above, those properties aren’t public. You’ll have to add them to a new header file and import it.

@interface SDataGridHeaderCell (PrivateProperties)
@property (nonatomic, assign) float leftIndentForTextView;
@property (nonatomic, assign) float rightIndentForTextView;
@property (nonatomic, assign) float topIndentForTextView;
@property (nonatomic, assign) float bottomIndentForTextView;
@end

Create a header file using the code above, and import it in the file where you call “setLeftIndentForTextView:3];”

These properties should be exposed in the next release, meaning you will no longer need this header file.

Regards,
Chris


#9

This works fine for the header. So how could I apply this to row cells too?

Thanks in advance,

Steve


#10

stevebrookes

This works fine for the header. So how could I apply this to row cells too?

Thanks in advance,

Steve

I was finally able to do it for both the header and the cell when creating the column with UIEdgeInsets, headerCellStyle.contentInset and cellStyle.contentInset as below:

// Set my padding for the cell.
	UIEdgeInsets padding = UIEdgeInsetsMake(5, 5, 5, 5);
	
	SDataGridColumn* column;

	column = [[SDataGridColumn alloc] initWithTitle:@"Part Number"];
	column.editable = NO;
	column.width = @175;
	column.headerCellStyle.contentInset = padding;
	column.cellStyle.contentInset = padding;
	[shinobiDataGrid addColumn:column];

Wg


#11

I tried both the private properties category and the Wg method setting the contentInset of cellStyle for column. They both seem to provide the desired setting of the padding but I lose the center alignment of the text. I tried setting the alignment of the cell.textField but that had no effect. Any fix for this?


#12

Greetings Program!

You will need to add the text alignment to the cellstyle as well:

// *************************************
	// Line column
	// *************************************
	SDataGridColumn *column = [[SDataGridColumn alloc] initWithTitle:@"Line"];
	column.editable = NO;
	column.width = @25;
	column.headerCellStyle.contentInset = padding;
	column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
	
	SDataGridCellStyle *cellStyle = [[SDataGridCellStyle alloc] init];
    cellStyle.font = font;
    cellStyle.contentInset = padding;
	cellStyle.textAlignment = NSTextAlignmentCenter;
	column.cellStyle = cellStyle;
    [shinobiDataGrid addColumn:column];

Wg