How could I go about reordering the data in a repeating panel?
I don’t mean sorting a data table, just a “move up/down” button for each row.
My initial thought was just to rearrange the data and reassign it to the items property, but I was wondering if there was a way to move the displayed order for a single “row” instead.
I’m further assuming we don’t have drag/drop facilities yet?
An example, using the 5th and 6th panels…
Plan A: You’d like to swap panel 5 for panel 6, while keeping the same data in each panel.
Plan B: Leave all the panels where they are, but swap each successive data item between panels 5 and 6.
Does that cover it?
Plan A has the advantage that it can probably be done as a single “transaction”. It’s either fully done or not done at all.
I’d like to swap the panels (plan A), because even though I said repeating panel I’ve thought about it and in actual fact I may end up using a mixture of line item forms instead, so the layout may also be different.
So I suppose my question is how can i reorder components (subforms) on a form without redrawing the whole thing again, or is redrawing the only way?
If you’re using a RepeatingPanel, then yes - you’ll have to set its items
property to a reordered list. (This is often faster than you might think. It’s usually a good idea to do something the simple way first!)
If you’re managing your own list with a LinearPanel, then you can insert components at any point in the list by passing the index=
parameter to add_component()
(see docs). This would let you remove and re-add a component wherever you like.
2 Likes
I’ve done it again - completely missed the docs where it says about the index.
Sorry, that was me firing off a question again without properly reading up.
Thanks.