Search widget not suggesting/ not displaying any result from feature layer

07-11-2019 02:40 AM
New Contributor

I have displayed a map using webmap and now trying to implement the search.. but it is not doing search in the feature layer.. What is wrong I am doing?

const testLayer = map.allLayers.find(function(layer) {
return layer.title === "mytestlayer";

var searchWidget = new Search({

view: view,
allPlaceholder: "Search",
sources: [
layer: testLayer,
searchFields: ["myfield"],
suggestionTemplate: "{myfield}",
exactMatch: false,
outFields: ["*"],
name: "testing",
placeholder: "example: test"

view.ui.add(searchWidget, {
position: "top-right"
0 Kudos
2 Replies
MVP Regular Contributor

Hi reneesh tk‌,

Please find below the code for a working example of a Search Widget searching a Feature Layer.

It searches a Feature Layer with Dutch municipalities ("Gemeenten"): and if you type Amster it will come up with the suggestion Amsterdam :)

You can see the page in action here: Aan de slag met ArcGIS JavaScript - Feature zoeken 

I hope this example will help you to get your code up and running.

Best regards,


<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>Aan de slag met ArcGIS JavaScript - Feature zoeken</title>
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;

  <link rel="stylesheet" href="">
  <script src=""></script>

      ], function(Map, Point, MapView, FeatureLayer, Search) {

      var map = new Map({
        basemap: {
          portalItem: {
            id: "7aea6fa913a94176a1074edb40690318" // Topo RD
	  var rdOrigin = new Point({
	    x: 155000,
	    y: 463000,
	    spatialReference: 28992
	  var view = new MapView({
	    spatialReference: 28992, 
	    container: "viewDiv",
	    map: map,
	    center: rdOrigin,
	    zoom: 3

      var featureLayerGemeenten = new FeatureLayer({
        url: "",
      popupTemplate: {
          // autocasts as new PopupTemplate()
          title: "Gemeente {Gemeentenaam} </br>CBS Code: {GM_Code}",
          overwriteActions: true

      var searchWidget = new Search({
        view: view,
        sources: [
          layer: featureLayerGemeenten,
          searchFields: ["Gemeentenaam", "GM_Code"],
          suggestionTemplate: "{Gemeentenaam} ({GM_Code})",
          exactMatch: false,
          outFields: ["Gemeentenaam", "GM_Code"],
          placeholder: "Zoek gemeente (naam of code)"
        includeDefaultSources: false
	  view.ui.add([searchWidget], "top-right");
  <div id="viewDiv"></div>
Esri Regular Contributor

We also have a hosted sample that shows how to work with the Search widget and setting the source to a FeatureLayer:

0 Kudos