How do I format display for suggestions with Search widget?

1308
6
06-17-2020 04:18 PM
Arne_Gelfert
Occasional Contributor III

So I'm using a search widget to search across multiple similar (same schema)  map services and have set things up to

where I get suggestions.

Upon selection of a suggestion "result", I've got some event handlers doing what I need them to do and it all works. But I just don't like how the suggestions are displayed. They are grouped by service/source including a header referencing that source something like this:

service1 : searchfield1, searchfield 2
record 1
record 2
record 3
service2 : searchfield1, searchfield 2
record 4
record 5
record 6
service3 : searchfield1, searchfield 2
record 7
record 8
record 9

I want all those records but without any references to what service they came from.

My Search widget looks like this:

this.superSearch = new Search({
          sources: list_of_services,
          map: this.map,
          popupEnabled: false,
          autoSelect: false, 
          enableSourcesMenu: false,
          enableSuggestions: true,
          maxSuggestions: 5,
          allPlaceholder: "Example: John Smith",   // I'm searching for names
          autoNavigate: false
}, "superSearch");‍‍‍‍‍‍‍‍‍‍‍‍

Is there a way to format this, i.e. drop the "category" header identifying the feature services I'm calling? Thanks.

0 Kudos
6 Replies
mdonnelly
Esri Contributor

Hi Arne,

I believe this is the standard behaviour for multiple sources for the search widget.

You would likely have to code your own solution to get the result you want.

Mark

Regards,
Mark
0 Kudos
Arne_Gelfert
Occasional Contributor III

Oh darn! That would be disappointing. I'm using this as part of a custom widget. Don't want to do more custom. It's hard to believe that with all the other silly parameters for tweaking they've crammed into Search, this can't be changed. Thanks, Mark.

Noah-Sager
Esri Regular Contributor

Hi Arne Gelfert‌, I wonder if the Search widget is the best option for your use case. I'd like to understand more about what you are trying to accomplish. It sounds like you are doing a query of multiple layers, but you also want to have the suggestions?

Also, with regards to the Search widget parameters you mentioned, I'd be curious to know why you feel this way. Please feel free to message me on GeoNet if you are interested in discussing this further. If there is a way we can help you and make the API or the documentation better, then I am all ears.

-Noah

0 Kudos
Arne_Gelfert
Occasional Contributor III

Thanks, Noah. That would be a very opinionated conversation on my end, I'm afraid. I think you guys should start by consolidating on one API version. That would make my life easier for starters. Haha. Can you have that done by Monday? Very few of my challenges with ArcGIS web development have been grounded in programming, specifically Javascript programming, challenges or GIS concepts. It's always been: use of a wrong version, inability to locate the right piece of documentation or demo, bugs, the pancake stack of layers of abstraction when using something like WAB and trying to custom develop for it.... On the flip side, it makes those moments a lot more meaningful when I get to say: "Holymoly, it's working!!!"

As for my issue described above, I wasn't able to remove those header sections in the suggestions display but instead managed to override the the meaningless value or "service_name + suggestionTemplate" by setting the name property in my feature layers:

var featureLayer = new FeatureLayer("http://sampleserver.....................",{
    name: <my more meaningful name>,
    outFields: ["*"],
    displayField: "dispField",
    searchFields: ["searchfield1","searchfield2"],
    suggestionTemplate: "${suggField1}"/ ${suggField2}",
    enableSearchingAll: false,
    exactMatch: false,
    minCharacters: 0
});

That actually looks kind nice.

Noah-Sager
Esri Regular Contributor

Arne Gelfert wrote:

Thanks, Noah. That would be a very opinionated conversation on my end, I'm afraid. I think you guys should start by consolidating on one API version. That would make my life easier for starters. Haha. Can you have that done by Monday?

Oops, it's Monday already; I'm behind the deadline! All jokes aside, I would still be interested in hearing your opinions. If you have the time and inclination, feel free to write up some of your thoughts and email them to me (or publicly post if you want). It is always good to hear feedback directly from the people.

Arne Gelfert wrote:

 

As for my issue described above, I wasn't able to remove those header sections in the suggestions display but instead managed to override the the meaningless value or "service_name + suggestionTemplate" by setting the name property in my feature layers:

Excellent, glad to hear you found a workaround, and thank you for sharing your solution here.

0 Kudos
by Anonymous User
Not applicable

Hey Noah!
I bet you don't even remember this thread, but I'm here now searching for solutions to my search widget problems. It would be very, very useful if there was another parameter you could define like "suggestionAttributeToDisplay" or something that would allow you to specify what attribute of the suggestion result gets displayed.