<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Custom Filtering Widget for FeatureLayer in Web AppBuilder Custom Widgets Questions</title>
    <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/custom-filtering-widget-for-featurelayer/m-p/859829#M11721</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Hello all,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to ESRI as well as JavaScript.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am currently trying to develop a custom widget that takes attributes of a field within a FeatureLayer and gives you the option to filter between them. So the structure would be this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---- [FeatureLayer]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;------ [FIELD]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;---------- [ATTRIBUTES: x,y,z,...,]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the widget then giving you the ability to input a FeatureLayer, a specific FIELD within the FeatureLayer and which&amp;nbsp;ATTRIBUTES within that&amp;nbsp;FIELD you would like to filter and outputting a drop down menu on the map as a selector.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code wise I have this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[FILE] main.ts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;//// preamble with all import [PACKAGE] from "PLACE".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//BaseMap&lt;BR /&gt;const map = new EsriMap({&lt;BR /&gt; basemap: "TYPE"&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Widget view&lt;BR /&gt;const view = new MapView({&lt;BR /&gt; map: map,&lt;BR /&gt; container: "viewDiv",&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//FeatureLayer&amp;nbsp;&lt;BR /&gt;const layer = new FeatureLayer({&lt;BR /&gt; id: "FIELD",&lt;BR /&gt; url: "URL",&lt;BR /&gt; outFields: ["FIELD"],&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;map.add(layer);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var&amp;nbsp;CustomFilter = new CustomWidget({&lt;BR /&gt; // VARIABLES HERE&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;view.ui.add(CustomFilter, "top-right");&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[FILE] and the corresponding CustomWidget.tsx file:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;/// &amp;lt;amd-dependency path="esri/core/tsSupport/declareExtendsHelper" name="__extends" /&amp;gt;&lt;BR /&gt;/// &amp;lt;amd-dependency path="esri/core/tsSupport/decorateHelper" name="__decorate" /&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;//// preamble with all import [PACKAGE] from "PLACE".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;@subclass("CustomWidget")&lt;BR /&gt;class CustomWidget extends declared(Widget) {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// CODE GOES HERE&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;export = FilterWidget;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;as a reference, I got it to work without being a widget using the following code;&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG style="font-weight: 400; "&gt;-----------------------------------------------------------------------------------&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;// Display a drop-down menu for filtering the FeatureLayer&lt;BR /&gt;var sqlExpressions = ["[ATTRIBUTE1]&amp;nbsp;=&amp;nbsp;[VALUE1] ", "&lt;SPAN&gt;[ATTRIBUTE2]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;[VALUE2]"&lt;/SPAN&gt;, "&lt;SPAN&gt;[ATTRIBUTE3]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;[VALUE3]&lt;/SPAN&gt;"];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;var selectFilter = document.createElement("select");&lt;BR /&gt;&amp;nbsp;selectFilter.setAttribute("class", "esri-widget esri-select");&lt;BR /&gt;&amp;nbsp;selectFilter.setAttribute("style", "width: 275px; font-family: Avenir Next W00; font-size: 1em;");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;sqlExpressions.forEach(function(sql){&lt;BR /&gt;&amp;nbsp;var option = document.createElement("option");&lt;BR /&gt;&amp;nbsp;option.value = sql;&lt;BR /&gt;&amp;nbsp;option.innerHTML = sql;&lt;BR /&gt;&amp;nbsp;selectFilter.appendChild(option);&lt;BR /&gt;&amp;nbsp;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;view.ui.add(selectFilter, "top-right");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Filter the drop-down menu options based on title attribute&lt;BR /&gt;&amp;nbsp;function setFeatureLayerViewFilter(expression: any) {&lt;BR /&gt;&amp;nbsp;view.whenLayerView(layer).then(function(featureLayerView: any) {&lt;BR /&gt;&amp;nbsp;featureLayerView.filter = {&lt;BR /&gt;&amp;nbsp;where: expression&lt;BR /&gt;&amp;nbsp;};&lt;BR /&gt;&amp;nbsp;});&lt;BR /&gt;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;selectFilter.addEventListener('change', function(event) {&lt;BR /&gt;&amp;nbsp;setFeatureLayerViewFilter((event.target as HTMLInputElement).value);&lt;BR /&gt;&amp;nbsp;});&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;Any help on how to get started writing this code or converting it into a widget would be much appreciated. I have tried gathering information on the ESRI ecosystem but I need a little more help if possible &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Thank you in advance&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Nov 2019 01:41:53 GMT</pubDate>
    <dc:creator>TommyNygaard</dc:creator>
    <dc:date>2019-11-12T01:41:53Z</dc:date>
    <item>
      <title>Custom Filtering Widget for FeatureLayer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/custom-filtering-widget-for-featurelayer/m-p/859829#M11721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Hello all,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to ESRI as well as JavaScript.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am currently trying to develop a custom widget that takes attributes of a field within a FeatureLayer and gives you the option to filter between them. So the structure would be this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---- [FeatureLayer]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;------ [FIELD]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;---------- [ATTRIBUTES: x,y,z,...,]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the widget then giving you the ability to input a FeatureLayer, a specific FIELD within the FeatureLayer and which&amp;nbsp;ATTRIBUTES within that&amp;nbsp;FIELD you would like to filter and outputting a drop down menu on the map as a selector.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code wise I have this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[FILE] main.ts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;//// preamble with all import [PACKAGE] from "PLACE".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//BaseMap&lt;BR /&gt;const map = new EsriMap({&lt;BR /&gt; basemap: "TYPE"&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Widget view&lt;BR /&gt;const view = new MapView({&lt;BR /&gt; map: map,&lt;BR /&gt; container: "viewDiv",&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//FeatureLayer&amp;nbsp;&lt;BR /&gt;const layer = new FeatureLayer({&lt;BR /&gt; id: "FIELD",&lt;BR /&gt; url: "URL",&lt;BR /&gt; outFields: ["FIELD"],&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;map.add(layer);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var&amp;nbsp;CustomFilter = new CustomWidget({&lt;BR /&gt; // VARIABLES HERE&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;view.ui.add(CustomFilter, "top-right");&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[FILE] and the corresponding CustomWidget.tsx file:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;/// &amp;lt;amd-dependency path="esri/core/tsSupport/declareExtendsHelper" name="__extends" /&amp;gt;&lt;BR /&gt;/// &amp;lt;amd-dependency path="esri/core/tsSupport/decorateHelper" name="__decorate" /&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;//// preamble with all import [PACKAGE] from "PLACE".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;@subclass("CustomWidget")&lt;BR /&gt;class CustomWidget extends declared(Widget) {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// CODE GOES HERE&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;export = FilterWidget;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;as a reference, I got it to work without being a widget using the following code;&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG style="font-weight: 400; "&gt;-----------------------------------------------------------------------------------&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;// Display a drop-down menu for filtering the FeatureLayer&lt;BR /&gt;var sqlExpressions = ["[ATTRIBUTE1]&amp;nbsp;=&amp;nbsp;[VALUE1] ", "&lt;SPAN&gt;[ATTRIBUTE2]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;[VALUE2]"&lt;/SPAN&gt;, "&lt;SPAN&gt;[ATTRIBUTE3]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;[VALUE3]&lt;/SPAN&gt;"];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;var selectFilter = document.createElement("select");&lt;BR /&gt;&amp;nbsp;selectFilter.setAttribute("class", "esri-widget esri-select");&lt;BR /&gt;&amp;nbsp;selectFilter.setAttribute("style", "width: 275px; font-family: Avenir Next W00; font-size: 1em;");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;sqlExpressions.forEach(function(sql){&lt;BR /&gt;&amp;nbsp;var option = document.createElement("option");&lt;BR /&gt;&amp;nbsp;option.value = sql;&lt;BR /&gt;&amp;nbsp;option.innerHTML = sql;&lt;BR /&gt;&amp;nbsp;selectFilter.appendChild(option);&lt;BR /&gt;&amp;nbsp;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;view.ui.add(selectFilter, "top-right");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Filter the drop-down menu options based on title attribute&lt;BR /&gt;&amp;nbsp;function setFeatureLayerViewFilter(expression: any) {&lt;BR /&gt;&amp;nbsp;view.whenLayerView(layer).then(function(featureLayerView: any) {&lt;BR /&gt;&amp;nbsp;featureLayerView.filter = {&lt;BR /&gt;&amp;nbsp;where: expression&lt;BR /&gt;&amp;nbsp;};&lt;BR /&gt;&amp;nbsp;});&lt;BR /&gt;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;selectFilter.addEventListener('change', function(event) {&lt;BR /&gt;&amp;nbsp;setFeatureLayerViewFilter((event.target as HTMLInputElement).value);&lt;BR /&gt;&amp;nbsp;});&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-----------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;Any help on how to get started writing this code or converting it into a widget would be much appreciated. I have tried gathering information on the ESRI ecosystem but I need a little more help if possible &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Thank you in advance&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2019 01:41:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/custom-filtering-widget-for-featurelayer/m-p/859829#M11721</guid>
      <dc:creator>TommyNygaard</dc:creator>
      <dc:date>2019-11-12T01:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Filtering Widget for FeatureLayer</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/custom-filtering-widget-for-featurelayer/m-p/859830#M11722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By the way the example code I provided is the tutorial code supplied here:&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/javascript/latest/guide/filter-a-feature-layer/" title="https://developers.arcgis.com/javascript/latest/guide/filter-a-feature-layer/"&gt;Filter a feature layer | ArcGIS API for JavaScript 4.13&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Basically I am looking to turn this into a widget &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2019 01:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/custom-filtering-widget-for-featurelayer/m-p/859830#M11722</guid>
      <dc:creator>TommyNygaard</dc:creator>
      <dc:date>2019-11-12T01:56:32Z</dc:date>
    </item>
  </channel>
</rss>

