Programmatically filter attribute table

5153
24
Jump to solution
06-17-2016 02:39 PM
Ravichandran_M_Kaushika
Occasional Contributor

dear Readers,

thank you for taking the time to read the contents of the post.

How to programmatically filter records of the attribute grid?

there is a filter menu that open a popup window which allows the users to select the column by which the condition should be applied.  it also provides the ability to add 1 or 2 more columns with the option to make it ANY or AND.\

Is there a way to perform this operation programmatically?

thanks and regards

ravi.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Frisky Weasel,

  I Have not tested this but it should be as simple as setting the expr to 1=1:

              var partsObj = { 
                "expr": "1=1", 
                "parts": [] 
              };  
              var activeTable = attWidget._tableFunctionController.getActiveTable(); 
              activeTable.setFilterObj(partsObj); 
              activeTable.refresh();

View solution in original post

24 Replies
AdrianWelsh
MVP Notable Contributor

Hi Ravi,

If you are using Web AppBuilder, you can add the Query Widget to your web app. Using this query widget can be an interactive filter than can create an operational layer which can be viewed in the attribute table.

Info on out-of-the-box query widget:

Query widget—Web AppBuilder for ArcGIS | ArcGIS

Info on developer edition query widget:

Query—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers

I hope this helps.

Ravichandran_M_Kaushika
Occasional Contributor

Adrian,

good afternoon.   thanks for replying quickly.  Sorry I did not give too many details and tried to keep the question simple.  To explain my situation, I have provide a detailed explanation as to why we want this.

Our feature n map server layer is of national extent. we implemented a widget using the sample blank widget template from ESRI with state/county/ and point feature layer names for a  guided navigation for 2 purposes:

1. to search a point feature by state/county as people using this might not know the actual geographic location,

2. lock down users based on the state they are allowed to view.

When a user who is allowed to work on California, the state dropdown has only 1 entry and when the users select that 1 entry, all other point features are hidden when  the application also zooms to California extent.  The application would load all the counties of CA.  NV state features are set to hidden from the feature layer display on the map element.  the attribute grid changes to reflect the dams in the new extent but contains NV and AZ state records.

What we want to accomplish is that when we are programmatically removing point features belonging to NV and AZ from the visible extent after the application zooms to CA, at the same time, we want to programmatically do something as though the user click on filter by attributes of the attribute table to set the NV and AZ point feautres to hidden.

We are already using eSearch wizard (by Mr. Robert S., GISP of AL) for our searching and report creation purposes.

thanks once again for your help.  have a good weekend.

regards

ravi.

0 Kudos
Ravichandran_M_Kaushika
Occasional Contributor

Adrian,

One of our ESRI support staff requested us to use Select by option instead of the on-demand option while loading another layer.  this is after the web map to facilitate the 'smoother' hiding of features in different state/county.

After we implemented the Select By option for the layer, the web app builder code does not know about the newly added Select by option layer and the jimu based WAB functions work fine with the on-demand layers that are coming from Web map residing in the portal.

right now with the on-demand feature layers coming from web map are working in a fine way with all other WAB functions and the only hitch is the attribute grid filtering.   so if we fix the attribute grid then we have addressed our end users' needs.

regards

ravi.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Ravi,

  I have done this for the vanilla JS API so I should be able to come up with something for the AT Widget too. I'll keep you posted.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Ravi,

  So here is the code to add to some function to apply a filter to the Attribute Table Widget. This assumes that you are going to have the AT widget loaded and open already:

You will need to add the WidgetManager require: 'jimu/WidgetManager'

        this.wManager = WidgetManager.getInstance();
        if (this.wManager) {
          var widgetCfg = this._getWidgetConfig('AttributeTable');
          if(widgetCfg){
            var attWidget = this.wManager.getWidgetByLabel(widgetCfg.label);
            if(attWidget){
              this.wManager.openWidget(attWidget);
              var partsObj = {
                "expr": "Crime_Type='Auto Theft'",
                "parts": []
              };
              console.info(attWidget);
              var activeTable = attWidget._tableFunctionController.getActiveTable();
              activeTable.setFilterObj(partsObj);
              activeTable.refresh();
            }
          }
        }

and here is the support function called above:

     _getWidgetConfig: function(widgetName){
        var widgetCnfg = null;
        array.some(this.wManager.appConfig.widgetPool.widgets, function(aWidget) {
          if(aWidget.name == widgetName) {
            widgetCnfg = aWidget;
            return true;
          }
          return false;
        });
        if(!widgetCnfg){
          /*Check OnScreen widgets if not found in widgetPool*/
          array.some(this.wManager.appConfig.widgetOnScreen.widgets, function(aWidget) {
            if(aWidget.name == widgetName) {
              widgetCnfg = aWidget;
              return true;
            }
            return false;
          });
        }
        return widgetCnfg;
      }

,

Ravichandran_M_Kaushika
Occasional Contributor

Robert,

good morning. thank you for the reply.  we will use the code and confirm it works.

thanks once again for your support to the entire js, WAB community.

regards

ravi.

0 Kudos
friskyweasel
New Contributor

Hello Robert! Your above code was absolutely perfect and exactly what we needed - thanks so much - just had one last quick question if you don't mind.

We implemented your code inside of our custom widget, but once the user is finished working with it and closes it, we would like to return the Attribute Table back to its original working application logic. In other words, clear out any custom filtering we have implemented via our "partsObj" expression, and have the Attribute table behave exactly as it did out of the box (display all items that fall within the currently displayed extent of the map).

Is there a simple technique for accomplishing this whenever our widget is closed? Thanks so much for your help!

0 Kudos
LefterisKoumis
Regular Contributor

Hello Robert. It seems that this solution cannot implemented with the latest WAB since tableFunctionController is no longer available. Do you have any alternative way?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

In 2.11 this is what you need:

var partsObj = {   
  "expr": "1=1",   
  "parts": []   
};    
var activeTable = attWidget._activeTable;   
activeTable.setFilterObj(partsObj);   
activeTable.refresh();