Perspective: How can I reorder array elements **and maintain bindings**?

v8.1.0rc1
Is there any way to rearrange property array elements and still keep the bindings intact within each array element’s objects? The only way I know of to rearrange elements is by copy/paste to text editor, rearrange, copy/paste back on top in Ignition, however this method doesn’t keep bindings intact…

It must be getting late… you can copy the json of the whole component itself, rather than just the array property. Although it’s not that easy, as you have to move the array element itself as well as reshuffle the indices of the bindings, and the bindings appear in the order in which they were created, not in the order of the index :confused: It’d be nice if there was a better way

You can’t change the order by dragging?

Nope :frowning:

Really, I must be confused on what you are saying because I’m able to reorder properties by dragging.

hmm, I’m in v8.1.0rc1, what are you running?

8.0.16

Weird, I definitely can’t click and drag them. I’m on Windows

Do you mind showing a picture just to make sure we are talking about the same thing?

I’m not at my laptop anymore but will in the morning. However to describe it, i’m talking about the properties of a component, e.g. A dropdown component’s data array property that configures the items available in the drop down menu. If I try to click and drag the array elements to move index 0 below index 1, nothing happens

I added a dropdown to a view, bound to a query and used format json. Then I unbound. I was able to drag and reorder. I grabbed to the right of the plus sign. I was also able to reorder the items under each “index”, however, for that to work I had to grab on the left side. It’s definitely clunky in my opinion.

You can re-order by dragging array elements. As @jlandwerlen suggested, you need to click-hold to the right of the element you’d like to re-arrange. This will NOT bring the binding along. You can’t supply a binding base don arbitrary relative positions to change if the position changes.

When you set up a binding within an array, it’s defined in the schema as custom.my_array[x].some_key. dragging the element to a different position results in the binding pointing to the original position because the x in the binding has not changed. If you need to re-arrange array elements and update bindings, it sounds like you should actually be using an object because that array position apparently means something more specific than an index would suggest.

bays: {
    "one": {},
    "two": {},
    "three": {}
}

is more correct than

bays: [
    0: {},
    1: {},
    2: {}
]
1 Like

That's interesting, when I tested earlier, it looked like the bindings went with it, but I only looked at the values, not the bindings themselves. When I closed and opened the view again the values updated and then I did notice what you are referring to.

While I understand that any runtime manipulations of the array cannot expect to have bindings adjusted, I’m a bit perplexed at the idea that the designer simply can’t move the bindings. The designer is making the edit, and it knows where the bindings are, so it should be possible to move the bindings with the edit. If someone were to make a feature request…

(It may still be an unfair comparison, but Vision is astonishingly good at manipulating bindings appropriately when editing windows and templates. This is a “polish” item for Perspective.)

1 Like

We do have a feature ticket open for something similar (the ticket only specifies updating bindings when an element is ADDED to an array), and I’ve made a note to consider any element movement. The problem with moving a binding is maybe I do NOT want the binding to move. Someone is going to request the opposite of whatever we do here, so we have to look at it like this:

Scenarios:

  1. User wants the binding on element y instead of element x.
    Solution: copy/paste the binding to element y and remove it from element x.
  2. User wants to move value from element x to element y.
    Solution: drag/drop - which does NOT bring the binding.

My case is, I have an SVG that I embedded - a simple square box. I set aspect ratio to none and then made it a wide and short rectangle to act as a bar chart for an analogue display. I copied the element so I had 5 rectangles, one each for: PV, and Alarm setpoints: HH, H, L, LL, below (L and LL set to 0).
image
image
Each element has a different clip-path style binding. However after creating and binding everything, I realised that I’d put the PV above everything else instead of behind… hence needing to move it to the top (to get it to the bottom :slight_smile: ), bindings intact.
(thanks again to @dkylep for that clip-path tip! Perspective Equivalent Vision Level Indicator? - #4 by dkylep)

If you deliberately bind to properties within an array element and want to move the element to another position, I personally can’t see a use case to not move the binding with it :thinking:

1 Like

What was the outcome of this? Did it ever get fixed?

Late, but no, this has not been fixed :frowning:

As of 8.1.39, bindings within arrays now move when their element of the array is re-ordered.

6 Likes