Need to reverse order of ListViews (Legends, Layers, etc.).

01-30-2018 07:09 AM
New Contributor II

Apps using web maps populate list views for things like legends, layer lists, etc., in the order that they appear in the underlying code in the web map, which is typically reverse of the way they appear in the web map's TOC (top layer is at the bottom of the list in the JSON). 

What's the easiest way to reverse the order of these list views so that they populate in the same order as the TOC?

0 Kudos
2 Replies
Esri Regular Contributor

HI Jeremy,

There can be multiple ways to solve this problem. One way I think you can work around it by using QML ListModel and instead of appending data (json object) you can use insert operation and always use index 0 while lopping through each layer. This way every layer will gets added in the ListModel as the first item as oppose to the Last item which what append operation does.



0 Kudos
Regular Contributor

Hi Nakul

If I can chime in on this one....!

In the previous runtime (10.2.x) I had to query the database and then populate a ListView with the results for things like layer lists etc. I had the exact same issue as Jeremy where the results came out in the wrong order, but because I was populating it 'manually' I could just as easily insert them in reverse or inserting at zero like you say.

I was excited about the new runtime returning List Models as it would be quicker and easier. But of course, if it's in the wrong order then we're pretty much back to square one, where we have to obtain the results and manipulate it ourselves - slower and more code....

I had hoped there would be some flag we could set that would return the results in reverse order? Since underlying it all I assume there is just a SQL query running, surely a flag could set an 'ORDER BY' of some sort?

It would be great and much more user friendly if it could all happen in the one call. Sounds like not possible right now, but maybe something that could easily be slipped into the next release?   



0 Kudos