Map Viewer Template Sorting

01-07-2020 04:20 PM
New Contributor II

I'm working with the Map Viewer template and I want the results returned from the Feature Search (SearchPage.qml) to be sorted.

I have a web map with 8 layers with 3 layers that have searching enabled.  For example I have a layer of parcels that I search by Owner Name and a Subdivision layer that I search by Subdivision Name.  When the results are returned I would like to have the Parcel results sorted by Owner Name and the Subdivision results sorted by Subdivision Name.  

As an example - when I search for Carlson (an owner name and a subdivision name) (or a floor cleaner and a dessert topping) I get the following unsorted results:

My users would really like the results to be sorted within each layer.  I've attempted to add orderByFields to the SearchPage.qml in the QueryParameters with mixed results.

    QueryParameters {
        id: featureParameters
        maxFeatures: 50
        orderByFields: [
            OrderBy {
                fieldName: "NAME";
                sortOrder: Enums.SortOrderAscending

Adding this also requires
featuresModel.sortByStringAttribute("layerName") to be changed to
featuresModel.sortByStringAttribute("NAME") in SearchPage.qml -> onFeatureSearchCompleted:

This works for the Parcel layer but not for the Subdivision layer.  It obviously only works for one layer.  I'm unsure how to add distinct query parameters for each layer that is being searched.  Doing this also drops the search results from the Subdivision layer.

I've looked at the sorts in CustomListModel.qml, but I've been unable to achieve my desired sorted results.

How can I modify the Map Viewer Template to sort the results of a feature search for each searched layer in my web map?

I'm sure there is a simple and elegant solution to this problem.  Any insight that you can provide will be greatly appreciated.

0 Kudos
1 Reply
Esri Regular Contributor


I think this can be done if we sort the result of each layer on the client-side.

For example, on MapViewer/view/SearchPage.qml on the signal OnFeatureSearchCompleted, the featuresModel is sorted by "layerName" attribute. The modification would around this logic. 

This is the function sortByStringAttribute on MapViewer/controls/CustomListModel.qml

I hope this is helpful,


0 Kudos