Select to view content in your preferred language

Add filtering to template picker

2955
3
Jump to solution
07-03-2016 06:51 AM
Haider_Ali
Frequent Contributor


I want to add search box that  will filter template picker on basis of its label, i have looked into  templatePicker.grid.store._arrayOfAllItems  it contains the items displayed in template picker with some extra items (extra items appears after every 3 item i think its because i have configured 3 columns in template picker settings )

my question is how can i filter this using it?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

Take a look at the FilterEditor.js file in this github repo. This is part of a Web App Builder widget but you could use the same logic in a custom app:

https://github.com/Esri/solutions-webappbuilder-widgets/blob/master/FilterEditor/FilterEditor.js

Here's a jsbin showing this in a test app:

JS Bin - Collaborative JavaScript Debugging

View solution in original post

3 Replies
Haider_Ali
Frequent Contributor

editor has a method filter tempEditor.templatePicker.grid.filter({label:"A*"}) but i cant figure out how to use it?

0 Kudos
KellyHutchins
Esri Frequent Contributor

Take a look at the FilterEditor.js file in this github repo. This is part of a Web App Builder widget but you could use the same logic in a custom app:

https://github.com/Esri/solutions-webappbuilder-widgets/blob/master/FilterEditor/FilterEditor.js

Here's a jsbin showing this in a test app:

JS Bin - Collaborative JavaScript Debugging

Haider_Ali
Frequent Contributor

Thanks to Kelly's Answer i also added  a  Layer select control ,below is the code (see the Kelly's Answer for more detail)

function _createTemplateFilter()
{
          widget._origGetItemsFromLayerFunc = widget._getItemsFromLayer;
          widget._getItemsFromLayer = lang.hitch(this, function () {
            var items;
            items = widget._origGetItemsFromLayerFunc.apply(templatePicker, arguments);
       
            items = arrayUtils.filter(items,(item) =>  (item.layer.layerId == select.value));
         
            return items;
          });
  }