Order Action Group Item by state

Is it not possible to order Action group actionGroupPopupItem by state falling.
I am displaying my energy consumption.

I don’t believe you have any input on the order when using the group action. You would have to build your own version of the widget and some advanced repeater manipulation to get a list like that sorted.

Would be worth to try if widgetOrder metadata would make any change.
For oh-repeater it works really well…

2 Likes

But even with oh-repeater you can not sort by state high to low.

Sorry, overlooked you want to sort by state.
In that case, it indeed does not help.

By using the map property of the repeater it can be made to sort by arbitrary things such as item state. It’s not trivial, but it is doable.

2 Likes

Does anybody have an example for a MAP based sort?

    - component: oh-repeater
      config:
        for: alphaTest3
        fragment: true
        in:
          - alpha1: cabbage
            alpha2: green
            name: Cabbage
            num1: 3
          - alpha1: apple
            alpha2: red
            name: Apple
            num1: 2
          - alpha1: banana
            alpha2: yellow
            name: Banana
            num1: 1
        map: loop.alphaTest3_source.sort((x,y) => (x.alpha2).localeCompare(y.alpha2))[loop.alphaTest3_idx]
        sourceType: array

This looks a little more complicated than it is. The map property applies the given expression to each element in the repeater array. We can sort the repeater source array using whatever sorting function we want (in this case an alphabetical comparison between the alpha2 properties of each object in the array), then we use the repeater index variable to map this repeater output to the equivalent element from the sorted array.

3 Likes