Feature Request: Move 2 items at a time.
Either as default or as a configurable option.
A common pattern in table is striped rows. Striped rows are commonly implemented as :nth-child(odd) selector. Currently, vertical-collection moves 1 item at a time. When this happens, the row strips shifts, creating a bad experience.
The current workaround is to precompute the even/odd rows and attach additional class on the row to preserve the strips.
If possible and not overly / unnecessarily complicated, adding the ability to group updates in batches of variable size (not only one and two, but n) might be even better.
You don't need to pre-compute if you use index to do it, although I generally agree that using :nth-child(odd) is nice.
@runspired: You don't need to pre-compute if you use
indexto do it
+1. I have solved it like this:
<VerticalCollection
as |item index|
>
<tr
class="_{{oddity index}}"
>
<Whatever @item=item>
</tr>
</VerticalCollection>
// helper
function oddity([value]: [number] /*, hash */): 'even' | 'odd' {
return value % 2 === 0 ? 'even' : 'odd';
}
tr {
&._odd {
background: white;
}
&._even {
background: lightgray;
}
}