Select to view content in your preferred language

Search box widget?

3190
16
Jump to solution
11-28-2016 10:19 AM
haThach
Regular Contributor

When a user enter a search for a particular record, can the result return display multiple field. We have a few duplicate valveID. Instead of returning v-155 three time can I config. the search result to display valveID and system field?

In C:\arcgis-web-appbuilder-2.1\server\apps\9\configs\Search\config_Search.json, I tried to change the displatField but the search did not work. Is this possible?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ha,

  So after checking the search widgets code in WAB the suggestionTemplate is not used in the code. It get it working you will have to add these lines of code to the search/Widget.js file (lines 16 - 19):

              var convertedSource = {
                featureLayer: flayer,
                outFields: ["*"],
                searchFields: fNames,
                displayField: source.displayField || "",
                exactMatch: !!source.exactMatch,
                name: jimuUtils.stripHTML(source.name || ""),
                placeholder: jimuUtils.stripHTML(source.placeholder || ""),
                maxSuggestions: source.maxSuggestions || 6,
                maxResults: source.maxResults || 6,
                zoomScale: source.zoomScale || 50000,
                infoTemplate: template,
                useMapExtent: !!source.searchInCurrentMapExtent,
                _featureLayerId: source.layerId,
              };
              if(source.suggestionTemplate){
                delete convertedSource.displayField;
                convertedSource.suggestionTemplate = source.suggestionTemplate;
              }

View solution in original post

16 Replies
RobertScheitlin__GISP
MVP Emeritus

Ha,

   You would have to add a suggestionTemplate property:

suggestionTemplate: "ID: ${ValveID}, System: ${System}",
0 Kudos
haThach
Regular Contributor

Thanks, Robert.  I tried your suggestion but it return the same three result. Am I missing something?

{
      "layerId": "AquaGIS_Search2_6622_1",
      "url": "MyServiceURL",
      "name": "Valves Search",
      "placeholder": "Place or Address",
      "searchFields": [
        "ValveID"
      ],
      "displayField": "ValveID",
      "suggestionTemplate": "ID: ${ValveID}, System: ${System}",
      "exactMatch": true,
      "searchInCurrentMapExtent": false,
      "zoomScale": 2400,
      "maxSuggestions": 6,
      "maxResults": 6,
      "type": "query",

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

No. You will only get the double field when a suggestion is presented by the widget.

0 Kudos
haThach
Regular Contributor

Robert,

Can you clarify this a bit. I'm currently using ArcGIS Server 10.4.1 which should Supports Pagination: true. I did get a suggest of a single field but not double field. Do I needs to add the system field to the property "displayField"?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ha,

   No if you read the documentation on the search widget you will see that the displayField can only contain one field name and the suggestionTemplate:

(Added at v. 3.14) A template string used to display multiple fields in a defined order. This only works with feature layer sources and takes precedence over displayField.

haThach
Regular Contributor

Thanks, Robert. It make sense know. I just have to switch my MapServer to  FeatureServer and the suggestion should be presented by the widget. Right?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nope. The use of a MapServer url is fine as long as you are adding a FeatureLayer as the search widgets source. The only reason to use a FeatureServer ul is when you want to edit that layer.

0 Kudos
haThach
Regular Contributor

Robert, you got me going in circle. It turns out that I'm already using a dynamic feature layer as a source for searching, which I published as a MapServer. Your suggestion of using a suggestionTemplate did not working for me.

Can you help me determine what I did wrong or point me to a direction of how to display multiple fields.

 

Thanks,

Ha

0 Kudos
deleted-user-CQZbjNeBXm49
Deactivated User

Ha,

What Robert by featurelayer via your mapserver is this: http://services.arcgis.com/b6gLrKHqgkQb393u/arcgis/rest/services/TaxParcelQuery/MapServer/0

Baba