brendand / mbtablegrid

An NSControl subclass which provides a spreadsheet-style table grid
9 stars 3 forks source link

Summary row should support popups for selecting the kind of data to display #10

Closed brendand closed 9 years ago

brendand commented 10 years ago

The summary row should provide a delegate to let it supply an NSPopupButton that lets you provide a set of options to switch between. For example, Total, Minimum, Maximum, Average, Count, if displaying aggregate data from the values in the associated main table grid's column.

Dejal commented 9 years ago

FYI, I've spent two hours thinking about a design for this. This is what I've come up with; let me know if you have any feedback. I'll implement it this afternoon.

Data source:

Footer view & cell:

Controller:

brendand commented 9 years ago

I don't think there's a need for the mode stuff. Really just need to know what type of cell to draw in the footer and let the datasource provide all the values to display plus a list of items for each popup if an NSPopupButtonCell is being used. You may want to display a count of the number of checked items, so for a checkbox column, you may still want a total displayed at the bottom. And for the rating column, you may just want to display "Average: 4.5" instead of the actual stars. But all of that can be determined by what type of footer cell is returned from the controller. The lower level code is only responsible for drawing the value obtained from footerValueForColumn.

brendand commented 9 years ago

I think a -tableGrid:setFooterValue:forColumn: method would be suitable to go along with the -tableGrid:footerValueForColumn: method. Then when the controller receives the value from the popup, it can do what it needs to do to remember that setting for next time.

Although the only issue with that is since the values displayed in the popup button are dynamic, the controller really just needs to know the index of the selected popup button item. It doesn't care about what value is displayed.

I'm envisioning something like this in the footer popup:

Total: $100.25 Average: $10.00 Minimum: $2.25 Maximum: $50 Count: 10

So also consequently the formatters wouldn't really apply in this situation. The number should be pre-formatted when they're displayed in the footer. It makes sense to have the formatters in the data cells because you want to catch input errors, etc. But the values in the footer aren't really changeable by the user other than to decide what is to be displayed.

Dejal commented 9 years ago

The reasoning was that the footer cell is reusable for multiple columns, so the table needs to tell it the value to display, plus the popup menu selection, since those aren't the same thing. I thought about making the cell figure out the display value itself, but that seemed less elegant, and inconsistent with the existing design.

Dejal commented 9 years ago

Ah, I just noticed that you edited your comment -- I didn't get a notification of that.

I had envisioned that the popup items would be fixed. If you want dynamic items, I'd need a data source method to update the items instead of the object value method. In this scenario, yes, a single pair of get/set methods for the popup selection would be reasonable, in addition to the popup refresh method.

If the cell wasn't a popup (e.g. the level indicator), it could use the get method to populate its value, in the same way as a content cell (and the update and set methods wouldn't be used).

Dejal commented 9 years ago

Though, we may still want a separate method for the display value, since there may not be enough room to show "Average: $10.00" in the footer. Having all the dynamic values in the popup is nice, but the footer display value should probably be shorter, either just "$10.00" or "Avg: $10.00".

brendand commented 9 years ago

I figured people could just widen the column to make it fit or yes, I could use "Avg: $10.00", but that's to be determined by the controller, not the grid control, so it shouldn't care about that.

This is how I currently do it with my NSTableView control:

screen shot 2015-02-26 at 4 17 09 pm

brendand commented 9 years ago

So I'm looking for something similar to that ^, but with the ability to have a popup there so I can change the default setting to display a different value.

Dejal commented 9 years ago

That's what I'll provide, then. I've simplified my design to fit with what you want, and have spent a couple of hours on it tonight, and will finish it tomorrow (perhaps about another 3 hours).

Dejal commented 9 years ago

I've now completed this. Take a look and let me know if you find any issues or want any tweaks.

150227 footer

brendand commented 9 years ago

:+1: