textAlignment in header with ShinobiDataGrid


#1

Hi,

I’m trying to set a text Alignment for the header of my ShinobiDataGrid.

I tried several different settings without being able to set the textAligment to NSTextAligmentRight.

Solution 1/

  SDataGridColumn* col = [[SDataGridColumn alloc] initWithTitle:obj];

  col.headerCellStyle = [[SDataGridCellStyle alloc] init];

  col.headerCellStyle.textAlignment = NSTextAlignmentRight;  

// does not work

Solution 2/

ShinobiDataGrid * grid = …

 grid.defaultCellStyleForHeaderRow.textAlignment = NSTextAlignmentRight;

//does not work, and the problem with this solution is that I cannot have a different header textAlignment for different column

Solution 3/

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

        cell.coordinate.column.headerCell.textField.textAlignment = NSTextAlignmentRight;

//does not work as well

Any ideas ?


#2

Hi,

You can just change the textAlignment property on the headerCellStyle of the column as follows:

SDataGridColumn* symbolColumn = [[SDataGridColumn alloc] initWithTitle:@"symbol"];
symbolColumn.headerCellStyle.textAlignment = NSTextAlignmentRight;
[grid addColumn:symbolColumn];

I’ll double check the various solutions you tried - at least method (1) and (2) should work.

Colin E.


#3

OK, I have checked both (1) and (2) - both work just fine. There must be some other issue with your code. If you are still having problem - please post a follow-up here.


#4

Hi Colin,

thanks for your quick answer.

textAlignment for header are indeed working fine, I just realized I was misguided by the indent space applied to the text inside the header. Sorry about that…

Do you know if there is way to adjust this indend space for headers ?

I just found another topic explaining how to modify the default value for cells (with the use of the property “leftIndentForTextView”) but I was not able ti use this trick for the header.

Thanks !


#5

I finally found a solution to get rid of the unwanted indent spaces in the header by applying a similar fix as the one used for the cells :

in shinobiDataGrid:prepareCellForDisplay:

   textCell.coordinate.column.headerCell.leftIndentForTextView = 5.0f;

    textCell.coordinate.column.headerCell.rightIndentForTextView = 5.0f;

Now titles in header are perfectly rendered and aligned.