Sub classing SDataGridCell


#1

Hi,

I’ve subclassed SDataGridCell to use a UILabel to display a text.

For applying style I have override the applyStyle: method of the SDataGridCell like below:

- (void) applyStyle:(SDataGridCellStyle *)style {
    [super applyStyle:style];
    _textLabel.textAlignment = style.textAlignment;
    _textLabel.textColor = style.textColor;
    _textLabel.font = style.font;
}

The default alignment for the _textLabel object is NSTextAlignmentRight.

And for changing the style for a particular column I’ve implemented the SDataGridDelegate’s method

– shinobiDataGrid:alterStyle:beforeApplyingToCellAtCoordinate:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid alterStyle:(SDataGridCellStyle *)styleToApply beforeApplyingToCellAtCoordinate:(SDataGridCoord *)coordinate {
    iMonGridColumn * column = [self.headers objectForKey:coordinate.column.propertyKey];
    if (column.columnIndex==0) {
        styleToApply.textAlignment = NSTextAlignmentLeft;
        styleToApply.textColor = [UIColor greenColor];
    }

But the alignment is not applied to the cell’s textLabel object, even the the delegate method is called propery for the set column index 0.


#2

Greetings Program!

You do not need the applyStyle method in your custom cell; you can remove it.

The delegate method fires before the applyStyles but it sets the style and does not pass the modified style to the applyStyle method. The applyStyle method receives the same SDataGridCellStyle as the delegate.

You’re better off setting the default style for the cell when you create the column:

// add an ask price column
    SDataGridColumn* askColumn = [[SDataGridColumn alloc] initWithTitle:@"Ask" forProperty:@"askPrice" cellType:[PriceCell class] headerCellType:[SDataGridHeaderCell class]];
    askColumn.width = @150;
    askColumn.sortMode = SDataGridColumnSortModeTriState;
	
    SDataGridCellStyle* style = [[SDataGridCellStyle alloc] init];
    style.backgroundColor = [UIColor yellowColor];
	style.textAlignment = NSTextAlignmentRight;
    askColumn.cellStyle = style;

	[_shinobiDataGrid addColumn:askColumn];

And if you want to override the default style on some condition, you can do it in the delegate:

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

or

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid alterStyle:(SDataGridCellStyle *)styleToApply beforeApplyingToCellAtCoordinate:(SDataGridCoord *)coordinate
{
    if ([coordinate.column.title isEqualToString:@"Ask"] && coordinate.row.rowIndex == 2)
	{
        styleToApply.textAlignment = NSTextAlignmentLeft;
        styleToApply.backgroundColor = [UIColor greenColor];
    }
}

Wg


#3

Hi

Is there is any way that we can change the sort symbol for a column?

The header row height I’m using is 36 pts. But the sort symbol provided is bigger than that of the font I’m using for header.

Also I have set the right contentInset for the header to 5pts with the text alignment as right. So header symbol overlapped by the header. Is there is more customization possible with header? Please provide your suggestions.

Header


#4

Have a look at this thread, it should help:

Wg


#5

Hi,

Thank you,

The header is not exactly coming up. But I will try tweaking it/

Which one should I use ShinobiGrid or ShinobiDataGrid? What is the difference?


#6

ShinobiDataGrid - it is the replacement for ShinobiGrid (and more powerful). Maybe you could get away by using ShinobiGrid for simple things but I’d just stick to ShinobiDataGrid for everything myself.

Wg


#7

Thanks Wwizgod,

_ Please ignore below query _. Updated the thread you have pointed out before.

Is there is any way I can style the columns. 

I followed the above implementation for custom sort symbol. As explained there I sub-classed the SDataGridHeaderCell.

But as the columns are reusing the header cells , and the each header cell is maintaining the state for SortOrder of column, when I scroll horizontally the header cell is moved to someother column with a wrong sort symbol displayed.