Repeat row question

I have a repeat row like this

<div class="row redrow" dmx-repeat:repeat1="api5.data.data.onwardflights.sort(`fare.grossamount`).groupBy(`searchKey`)">

I would like to bind data inside the repeat as i normally would but I only want to display a single result instead of multiple. I have to use the repeat to get all the data so i can group and sort it first.
I tried returning a single result like this but it gives multiple results

<div class="col-12 col-sm-6 text-center airline-output" dmx-hide="$index > 0"><h4>Airline</h4>{{$value[0].airline}}</div>

So to get around it i do something i am ashamed of which is that dmx-hide="$index > 0"

LOL, any ideas to do it better please.

its an array
so put [0] to get the first record in the data

I tried that already but no matter where i put the [0] i could not get it to do what i wanted.

Can you show me where on that please.

EDIT: The above code is what i have now, that gives me all the data from the first groupBy, tried doing {{$value[0][0].airline}} to get the first record from the first Group.

I don’t know the structure of your data, but try:

{{api5.data.data.onwardflights.sort('fare.grossamount').groupBy('searchKey').values()[0].airline}}

I would not use a repeater if you only wanted to get a single value.

1 Like

Thanks so much Patrick, that taught me something very valuable
I so no have to be inside a repeat to sort an array, I thought i HAD to, like no other option.
This opens up a whole new world of possibilities to me, thank you.

This is what I landed up having to do to get it working, seems it is a hefty multidimensional array returned.

{{api5.data.data.onwardflights.sort(`fare.grossamount`).groupBy(`searchKey`).values()[0][0].airline}}

Sorry one more slightly strange question here

is there a speed advantage of these 2 solutions

Solution 1 (I think I am querying the data twice and sorting twice and grouping twice)

{{api5.data.data.onwardflights.sort(`fare.grossamount`).groupBy(`searchKey`).values()[0][0].airline}}
{{api5.data.data.onwardflights.sort(`fare.grossamount`).groupBy(`searchKey`).values()[0][0].fare.grossamount}}

Vs Solution 2 (By adding the core into a variable I should only be sorting and grouping once and then just extracting what i need, but the var has much more unused data than in solution 1)

<dmx-value id="var1" dmx-bind:value="api5.data.data.onwardflights.sort(`fare.grossamount`).groupBy(`searchKey`).values()[0][0]"></dmx-value>
{{var1.value.airline}}
{{var1.value.fare.grossamount}}

So I am a little unsure here.

For performance the second solution is better, you indeed only do all the sorting only once.

1 Like

Thanks so much for confirming that now i am busy trying to add failover to my geo checking solution, this actually works by the way, never thought it would but it does.

dmx-param:lat="(geo1.status == 'OK') ? geo1.coords.latitude : api1.data.geoplugin_latitude" dmx-param:long="(geo1.status == 'OK') ? geo1.coords.longitude : api1.data.geoplugin_longitude"

So it uses Wappler coords if the user has it set to allow and IP Geolocation if they block it.

haha.