cloudflarearchive / backgrid

Finally, an easily stylable semantic HTML data grid widget with a Javascript API that doesn't suck.
http://backgridjs.com
MIT License
2.01k stars 325 forks source link

Get parent from child #548

Closed rajmohanh closed 9 years ago

rajmohanh commented 9 years ago

Hi, Is there a way in which we can get the parent view from a child view? In my case, I want to get the Grid object from a cell - is there any way to do that? My reasoning is as follows: I have a grid, collection and cells. Based on where the grid is called from, the cells should have minor behaviour differences. i.e. So when I am calling from foo, I want cell to behave a little differently from when I am calling from Bar. The collection is the same.

Now the only way I could see is by creating different cell types (Cell A and Cell B), which then I set in the columns differently based on where I call it.

I think a better and more correct approach is to have the grid itself different based on inheritance. Then when I am calling from foo, I set a parameter which tells the grid this semantic information. If I can get the parent object from the cell, I can check based on this parameter and behave accordingly.

Please let me know whether it is possible - and if not, do you feel it is a good idea for future addition

bruno-c commented 9 years ago

No, there isn't any way baked into the library to do this. On purpose -- to avoid dependencies between the components.

You can communicate "upwards" with events, triggered on the collection for example. But for what you are describing, subclassing the cells makes more sense.