-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lack of childViewContainer
in Marionette 3 makes valid table layouts difficult.
#3150
Comments
@blikblum Yes, I read that (and linked to it in my description). It doesn't address a case with no wrapper around the list of children. Thanks though! |
@jgerigmeyer you brought up an interesting problem. Could you set up a fiddle for this, please? I'm thinking about using |
Sorry not reading your issue carefully |
Use |
@paulfalgout Won't that cause indexing bugs with a sorted collection if models are added later? It also adds complexities with sorting/reordering, changing the |
this issue is looking related to #3128 where
|
@jgerigmeyer for this fiddle you can use but yes.. you will have to manage the view added in regards to sorting / filtering But in this case collectionView sorting/filtering will work without any effort. you should be able to add/remove to the collection with sorting.. also list3.viewComparator = 'thing2';
list3.resortView(); will work as well as list3.setFilter(function(child){ return child.get('thing1') !== 'Baz'; }); If you ever get a more complicated addition you might need to handle the index of the added view inside the filter.. or possibly do some more complicated switcheroos for maintaining a sort order (like say you wanted insert headings every 50 rows) but in those cases I don't think CompositeView is any better anyhow. |
Just dropping a brief code comparison for visuals. I think this supports what is being asked: In v3 const List = Mn.CompositeView.extend({
childView: Item,
onRenderChildren () {
this.addChildView(myHeadView, 0);
}
}); In v2: const List = Mn.CompositeView.extend({
template: '#list',
childViewContainer: 'table',
childView: Item
}); |
@jgerigmeyer is this resolved? |
@paulfalgout Ok, yeah I think that works. If I want to use Generally, I find @rafde's solution a bit cleaner, because I don't need to worry about introducing indexing bugs down the road, and I'm not using the undocumented Thanks all! I'll leave it up to the maintainers to decide whether this use-case deserves better documentation or a cleaner API. |
Whichever solution works for you as long as we're covering the edge cases for remove |
For anyone following along at home, I want to note that the recommended solution above (#3150 (comment)) isn't quite as straightforward as it seems.
const minIndex = _.min(this.children.map((child) => child._index));
this.addChildView(myView, minIndex); I would still argue that this (having additional markup outside the list of children) should be a feature/option built into a CollectionView. I'll try to think of a proposal or PR that could solve this in a nicer way. |
True for 1 if using reorderOnSort. I think for 2, that might be fixed already in the upcoming 3.1 and if not I would expect it in 3.2. @rafde is the index issue already resolved or is it an add issue? Also I have no idea what will happen off hand, but you could try |
😢 I can't resolve re-index until I properly resolve #3173 I can prioritize that work instead of the benchmark stuff, seems to be a need to resolve that PR. |
Description
I have a table layout (
<table>
) where I would like each item in acollection
to render as a<tbody>
. For example, the goal is markup such as:In Marionette 2, I was able to use a
CompositeView
:With the following
#item
template:And the following
#list
template:Because I used the
table
as thechildViewContainer
, the children were simply appended.With
CompositeView
now being deprecated in Marionette 3, I'm not sure how to get the same end result without adding an extra layer. And I can't really add an extra layer if I want valid table HTML. From reading the documentation, it seems like the approved new way to do this is to use aView
wrapper that shows aCollectionView
in aregion
(probably usingreplaceElement: true
). But unless I'm missing something, that still adds one layer (because theCollectionView
needs anel
of its own). The examples in the docs assume that the CollectionView can be atbody
, and the individual items can betr
s. But if I need the items to betbody
s, I need a way to render the collection without any wrapper of its own.It seems like the concept of a
CollectionView
that both renders a template and renders children in achildViewContainer
has been removed in Marionette 3, without a good replacement. I suppose I could override theCollectionView
render
function to render a template as well as the children?What am I missing here? Is there a recommended way to do table layout like this?
Environment
Update: You can see the way I was doing this with Marionette v2--along with my attempt to upgrade to Marionette v3--here: https://jsfiddle.net/jgerigmeyer/L3ttz0k4/
The text was updated successfully, but these errors were encountered: