Order Action Group Item by state

    - 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