Select to view content in your preferred language

Attribute filtering FeatureTable in JS 4.x

512
1
Jump to solution
06-25-2023 05:18 PM
patryks
New Contributor III

Is there a way to filter FeatureTable by attribute? I found similiar question but for version 3.x and it requires to implement custom input field for each column. 

https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-it-possible-to-filter-the-feat...

Maybe version 4.x does support such functionality out of the box? 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LefterisKoumis
Regular Contributor II

I created a widget to duplicate the functionalities of the filtering of the AT in WAB. 

This is the main core of the widget. For the selected layer, I have a dropdown listing all fields and another  dropdown for all values of the selected field where the user can create their SQLwhere statement. I hope it helps.

 

const getQuery = async (SQLwhere) => {
  let thelayer = theselectedlayer;
  let query = thelayer.createQuery();
  query.where = SQLwhere;
  let thevalues = [];
  // query.orderByFields = selectedField;
  query.outFields = ["*"];
  query.returnDistinctValues = false;
  query.returnGeometry = true;
  thelayer
    .queryFeatures(query)

    .then((results) => {
      console.log(results);
      if (results.features.length === 0) {
        document.getElementById("Message_html").innerHTML =
          "Query returned no features.";
        return;
      }
      if (featureTable) {
        featureTable.selectRows(results.features);
      }

 

 

View solution in original post

1 Reply
LefterisKoumis
Regular Contributor II

I created a widget to duplicate the functionalities of the filtering of the AT in WAB. 

This is the main core of the widget. For the selected layer, I have a dropdown listing all fields and another  dropdown for all values of the selected field where the user can create their SQLwhere statement. I hope it helps.

 

const getQuery = async (SQLwhere) => {
  let thelayer = theselectedlayer;
  let query = thelayer.createQuery();
  query.where = SQLwhere;
  let thevalues = [];
  // query.orderByFields = selectedField;
  query.outFields = ["*"];
  query.returnDistinctValues = false;
  query.returnGeometry = true;
  thelayer
    .queryFeatures(query)

    .then((results) => {
      console.log(results);
      if (results.features.length === 0) {
        document.getElementById("Message_html").innerHTML =
          "Query returned no features.";
        return;
      }
      if (featureTable) {
        featureTable.selectRows(results.features);
      }