Select to view content in your preferred language

How to query server-side FeatureTable?

393
11
Jump to solution
08-14-2024 02:11 PM
ForrestLin
Frequent Contributor

Is it possible to query server-side FeatureTable without re-creating FeatureLayer?

 

 

Tags (1)
1 Solution

Accepted Solutions
ForrestLin
Frequent Contributor

I got a solution:

1. Create FeatureLayer:

       let featureLayer= new FeatureLayer({

              url,
              objectIdField: "OBJECTID",
              definitionExpression: "OBJECTID<0", // Make featureLayer no feature initially
             popupTemplate,
             renderer
         });
 
2. Add featureLayer to map:
        view.map.add(featureLayer );
 
3. Create FeatureTable with featureLayer:
     const featureTable = new FeatureTable({
                   layer: featureLayer,  
                   view,
                   container,
                   returnGeometryEnabled: true
     }); // FeatureTable has no record initially
 
4. Query FeatureLayer using definitionExpression:
        featureLayer.definitionExpression = query;
 
5. Update FeatureLayer using refreshand FeatureTable got updated:
       featureLayer.refresh();

View solution in original post

0 Kudos
11 Replies
MatthewDriscoll
MVP Alum

You can bring it in as a FeatureLayer and query it the same as you would as a feature layer.

 

 

const bldPermLayer = new FeatureLayer({
    url: "https://.../server/rest/services/...",
    outFields:["*"]
});

const featureTable = new FeatureTable({
    view: theView,
    layer: bldPermLayer,
    
});

function handleQueryResults() {

    let queryBP = bldPermLayer.createQuery();
    queryBP.where = "query"
    queryBP.outFields = ["*"];
    // do the query 
    bldPermLayer
        .queryFeatures(queryBP)
        .then((response) => {
           // code 
        });
}

 

0 Kudos
ForrestLin
Frequent Contributor

@MatthewDriscoll 

Thank you for your help!

Is it possible that FeatureTable get updated automatically when querying FeatureLayer?

0 Kudos
MatthewDriscoll
MVP Alum

What do you mean?  Are trying to edit a FeatureTable through a query?

0 Kudos
ForrestLin
Frequent Contributor

@MatthewDriscoll 

function handleQueryResults() {

    let queryBP = bldPermLayer.createQuery();
    queryBP.where = "query"
    queryBP.outFields = ["*"];
    // do the query 
    bldPermLayer
        .queryFeatures(queryBP)
        .then((response) => {
           // code 
        });
}

The  response is FeatureSet, right? How to update FeatureTable using the response? Or FeatureTable got updated already?

Thanks.

Forrest

0 Kudos
MatthewDriscoll
MVP Alum

Do what you want with it in the code.  It's the same data so it could go something like below. 

 

function handleQueryResults() {

    let queryBP = bldPermLayer.createQuery();
    queryBP.where = "query"
    queryBP.outFields = ["*"];
    // do the query 
    bldPermLayer
        .queryFeatures(queryBP)
        .then((response) => {
           featureTable.selectRows(response.features);
           featureTable.filterBySelection(); 
        });
}
0 Kudos
ForrestLin
Frequent Contributor

@MatthewDriscoll 

Thank you so much for your help!

The total number of features in my FeatureLayer is about 500,000. I just need to get/query/search about 20 features each time, and then show them in the FeatureTable.

I don't want to create a new FeatureLayer and add to map each time I query. What should I do?

 

Forrest

0 Kudos
MatthewDriscoll
MVP Alum

You don't need to create a new FeatureLayer each time, just query off the one every time.  In fact you don't need to add the FeatureLayer to the map at all.  You might need to loop through the response.features, but not sure that is necessary.   

0 Kudos
ForrestLin
Frequent Contributor

I'm not sure how to update FeatureTable using the response.features.

These are just for selection of FeatureTable , not updating FeatureTable :

    featureTable.selectRows(response.features);
    featureTable.filterBySelection(); 

0 Kudos
ForrestLin
Frequent Contributor

I got a solution:

1. Create FeatureLayer:

       let featureLayer= new FeatureLayer({

              url,
              objectIdField: "OBJECTID",
              definitionExpression: "OBJECTID<0", // Make featureLayer no feature initially
             popupTemplate,
             renderer
         });
 
2. Add featureLayer to map:
        view.map.add(featureLayer );
 
3. Create FeatureTable with featureLayer:
     const featureTable = new FeatureTable({
                   layer: featureLayer,  
                   view,
                   container,
                   returnGeometryEnabled: true
     }); // FeatureTable has no record initially
 
4. Query FeatureLayer using definitionExpression:
        featureLayer.definitionExpression = query;
 
5. Update FeatureLayer using refreshand FeatureTable got updated:
       featureLayer.refresh();
0 Kudos