Filtering a webmap layer within a web appbuilder application on startup

5057
24
Jump to solution
05-24-2017 01:03 AM
SvivaManager
Occasional Contributor II

Hello,

Is there any way for me to filter a layer on startup of an application?

My current solution was to publish the same layer twice in a web map service. One layer shows all records. The other one is filtered by date.

I want to have only one layer published and when the user starts the appilcation, filter it by date and let him do as he pleased.

Is there a way to configure a widget with a certain filter to kick-in on startup?

Regards,

Shay.

24 Replies
DasheEbra
Occasional Contributor

@RobertScheitlin__GISP  I want to apply same approach on Group Filter widget, could you guide me!

also if it possible I want to render selected layers only from the Group Filter selection but if no selection then no layers  appeared (same as Render only when selected in Dashboard).

0 Kudos
VarmaThulasi
New Contributor II

Hi, Robert Scheitlin, GISP‌,

I also have the same requirement, When a user open the app, Firstly the Filter widget need to be open / pop up and request the filter value. I tried with your code and ended as with an error message. I am using Developer Edition 2.12 and my post create Function code block is different as you specified here.

this is my post create function:

 postCreate: function(){
        this.inherited(arguments);
        this._store = {};
        this.layerInfosObj = LayerInfos.getInstanceSync();
        this.filterUtils = new FilterUtils();
        this.filterManager = FilterManager.getInstance();

        if(this.config.allowCustom){
          html.setStyle(this.showCustomButtonNode, 'display', 'block');
          jimuUtils.initLastFocusNode(this.domNode, this.showCustomButtonNode);

          this.own(on(this.customFilterContainerNode, 'keydown', lang.hitch(this, function(evt){
            if(evt.keyCode === keys.ESCAPE){
              evt.stopPropagation();
              focusUtil.focus(this.customBackNode);
            }
          })));
        }

        var existAskForValue = false;

        var filters = this.config.filters;

        //set filters's order by layer
        if(this.config.groupByLayer){
          var newFilters = {};
          array.forEach(filters, function(filterObj) {
            if(!newFilters[filterObj.layerId]){
              newFilters[filterObj.layerId] = [];
            }
            newFilters[filterObj.layerId].push(filterObj);
          }, this);

          var lastFilterKey = '';
          for(var _key in newFilters){
            lastFilterKey = _key;
          }
          for(var key in newFilters){
            // for(var key = 0; key < newFilters.length; key ++){
            var layer = this.layerInfosObj.getLayerInfoById(key);
            // var layerName = this.layerInfosObj._getLayerTitle(layer); //don't use private function
            var layerNameNode = document.createElement('div');
            html.addClass(layerNameNode, "filter-layer-name");
            layerNameNode.innerText = layer.title;
            html.place(layerNameNode, this.filterList);

            var isCheckLastNode = (key === lastFilterKey) ? true: false;
            existAskForValue = this._initFilters(newFilters[key], existAskForValue, isCheckLastNode);
          }
        }else{
          existAskForValue = this._initFilters(filters, existAskForValue, true);
        }

        if(!existAskForValue){
          html.addClass(this.domNode, 'not-exist-ask-for-value');
        }
      }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Varma,

   I see nowhere in your code that you are calling:

query('.header', node)[0].click();
0 Kudos
VarmaThulasi
New Contributor II

Dear Robert Scheitlin, GISP‌ 

Please can you explain little bit ? Where I need to place this code. I have only one filter widget in my app and its have two filter. Thanks in advance.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Varma,

  Look at the original correct answer on this thread I point out that lines 38 - 40 are what need to be added to make the widget automatically run the query that is named ParksFinder in the widget. 

0 Kudos