Discover the Search widget

24529
65
03-06-2015 05:59 PM
MattDriscoll
Esri Contributor

There’s a new way to easily search your mapping data.

The ArcGIS JavaScript API’s new Search dijit precedes the Geocoder dijit (now deprecated). It’s been re-imagined, renamed and redesigned to provide a single searching and suggestion experience. It allows you to search across multiple Locator and Feature Layer services from a simple interface.

Whereas the Geocoder dijit’s intention was for searching only Locator tasks, the Search dijit was designed to handle multiple types of “sources,” including Locator tasks, Feature Layers and potentially more. The user interface has also been improved to handle searching one more of these sources. With the Search dijit, you can search or get suggestions from all the defined sources or a single source.

Much of the same functionality found in the Geocoder widget is also present in the Search dijit, but many new features have been added and redesigned for a better user and developer experience. As a developer, it should be easier for you to configure the Search widget and less code to write in order to handle common searching tasks. The icons for the widget use a font, so properties like the color or size can easily be modified.

New Features include:

  • Ability to search and get suggestions from Feature Layers
  • Automatically add Feature Layers from a map to the widget
  • Display additional search results to a user in the popup as “more results”
  • Highlight a result with a symbol
  • Label a result with a text symbol.
  • Results for suggestions and searches are separated and have different events
  • Optional button-mode to expand or collapse the search interface from a single button
  • Easily set an InfoTemplate to display custom popup information for a result
  • Individual placeholders for each search source... and more

Have fun exploring the demos or implementing it in your app.

65 Replies
JohnRitsko
New Contributor III

How I do it is that I simply don't declare s.set("activeSourceIndex", 0);  This for me will simply select ALL as the default.  I set my sources though but don't pick which one I want and as such it defaults to ALL.

JonathanBailey
Occasional Contributor III

Interesting -- that approach isn't working for me. If I don't set activeSourceIndex, the first geocoder in the list (after All) is selected.

0 Kudos
JonathanBailey
Occasional Contributor III

But I can do this:

s.set("activeSourceIndex","all);

and "All" is selected by default.

0 Kudos
DaveHighness
Occasional Contributor II

I would like to change the "placeholder" for the "All" selection from "Find address or place name" to just "Place name". I can't figure out how to change the placeholder for the "All" selection. I do know where to change it for the other feature layer sources that I specified.

0 Kudos
MattDriscoll
Esri Contributor

You can set the "allPlaceholder" property on the widget. I'll get that doc'd.

DaveHighness
Occasional Contributor II

Perfect!

0 Kudos
by Anonymous User
Not applicable

Is it possible to disable the 'All' search option?

0 Kudos
MattDriscoll
Esri Contributor

Yes, set the "enableSourcesMenu" to false.

Search | API Reference | ArcGIS API for JavaScript

0 Kudos
by Anonymous User
Not applicable

Yes I've read the documentation, maybe my question wasn't clear. I need the sources menu so that I can offer multiple layers from our server to search. However, a user must choose a layer. I do not want there to be an "All" option in the sources menu.

0 Kudos
MattDriscoll
Esri Contributor

Oh ok. I'll make an enhancement request for that. Currently, if you have multiple sources, you can choose between a source or "All". I'll have to add an option for "All" to be disabled.