Saulis / iron-data-table

iron-data-table is a Web Component for displaying data as a table or grid. Built on top of iron-list using Polymer.
Apache License 2.0
147 stars 65 forks source link

Expanding only one row at a time #114

Closed gdavalos closed 8 years ago

gdavalos commented 8 years ago

Is there a way to make it so that expanding a row closes any other row expanded previously?

So far, we tried adding a column with a button that calls a function which has the expand/collapse logic but we couldn't access to the expanded property nor to the item data through the event's model so we can't handle the expanded state there.

Are we going the right way? Is there another better way or doing it? Or is it just not possible with the current version?

Saulis commented 8 years ago

You can try iterating through _expandedItems and calling collapseItem for each before expanding the currently clicked row.

gdavalos commented 8 years ago

Thanks, that worked just fine, then again, wasn't using "private" properties from outside the element discouraged by the Polymer team?

Saulis commented 8 years ago

@gdavalos yes that's right, private properties should be avoided because they might get changed or removed. In this case you can trust the author, _expandedItems isn't going anywhere, I'll probably make it public at some point.

Saulis commented 8 years ago

I'm thinking on adding events like expanding-item and collapsing-item which you can grab and call event.preventDefault() to cancel the default behavior and substitute with your own. How does it sound like to you?

gdavalos commented 8 years ago

Would you send the item as a detail or something? If so, then it might be useful for this use case (and maybe some others)

Saulis commented 8 years ago

Yes sure item would be included, the implementation would similar as I sketched out for selection in the branch item-selection-events