Add columns aligned data to a grid section header


#1

I have a grid with section headers. Is it possible to add additional data to the header so that it is aligned with the columns in the grid? For example, if I have the sum of values of the different columns in that section, could I display these values correctly aligned under their corresponding header?


#2

Hi @canderson,

I’m struggling to visualize what how you want the headers to look - would you be able to post a mockup? That would help us to work out the best way to help.

It might also help to take a look at our grids samples on GitHub to see if any of the samples do something similar to what you’re trying to achieve.

Alison


#3

Here is an example from our desktop app that I would ideally like to mimic reasonably closely in our Xamarin.iOS app.

Basically the header section will have a string title (such as Folder: ASAP) that could span the width of more than one column. This is part of the reason I have been looking at using the built in section headers. Certain other columns have totals (or averages or other calculations that I already currently handle) that need to be displayed in the section row, aligned under the column header.


#4

Hi @canderson,

Thanks for the screenshot. I’d missed that it was the section headers you were asking about rather than the header rows, so I’m sorry if the github link was unhelpful.

Although there’s no way to implement cells in section headers automatically, you can provide a UIView for each section header via the shinobiDataGrid:viewForHeaderInSection:inFrame: method on SDataGridDataSource. So you could create a view with the given frame size, then if you know how wide your columns are, you should then be able to add UITextViews to your view at the correct positions, with appropriate alignments.

I hope that helps - let us know if you need any further help.

Alison


#5

If the column sizes aren’t really predictable, is there a convenient way to get the location in the grid of a column, or would I be better of just iterating over the list of columns, querying their width and adding them together? Is there a padding that I need to take into account for that calculation? How about the default padding used in the cells so that I can line up the calculated value in the section header, is there a way to know that?


#6

Hi canderson,

The easiest way to get this to work would be to specify column widths when initializing the columns (at least the ones above which you want the totals). If you do that you can then use the widths to position your text views correctly.

If you need to calculate the widths on-the-fly, you can use each column’s headerCell as a guide to the current width, but note that this will only work for columns which are currently on the screen.

The easiest way to get the contents to line up is to set the contentInset property on each column’s cellStyle. You can then use the same values as the contentInset on your text fields.

I hope that helps.

Alison