Select to view content in your preferred language

FeatureTable - Get Selected Rows

2472
5
Jump to solution
03-26-2022 07:08 AM
Ranga_Tolapi
Frequent Contributor

How to get the list of selected rows from Feature Table without using the "selection-change" event of FeatureTable? Is there any straight method or way to get the selected rows?

0 Kudos
1 Solution

Accepted Solutions
JeffreyWilkerson
Frequent Contributor

Ranga,

Everytime the table's 'selection-change' event is fired it provides a list of rows added or removed from the selection.  So after you set up the FeatureTable, set up a watch on that event such as:

// Get the FeatureLayer's layerView and listen for the table's selection-change event
// Here I'm maintaining a list of features for use elsewhere
let lstFeatures = [];
aFTable.on("selection-change", function (changes) {
    var idxItem = 1;
    // If the selection is removed, remove the feature from the array
    changes.removed.forEach(function (item) {
        const data = lstFeatures.find(function (data) {
            return data.feature === item.feature;
        });
        if (data) {                    
            lstFeatures.splice(lstFeatures.indexOf(data), 1);
        }
    });

    // If the selection is added, push all added selections to array
    changes.added.forEach(function (item) {
        const feature = item.feature;
        lstFeatures.push({
            feature: feature
        });
    });
    zoomToSelectedFeature(aLayer, lstFeatures, aView);
});

View solution in original post

5 Replies
JeffreyWilkerson
Frequent Contributor

Ranga,

Everytime the table's 'selection-change' event is fired it provides a list of rows added or removed from the selection.  So after you set up the FeatureTable, set up a watch on that event such as:

// Get the FeatureLayer's layerView and listen for the table's selection-change event
// Here I'm maintaining a list of features for use elsewhere
let lstFeatures = [];
aFTable.on("selection-change", function (changes) {
    var idxItem = 1;
    // If the selection is removed, remove the feature from the array
    changes.removed.forEach(function (item) {
        const data = lstFeatures.find(function (data) {
            return data.feature === item.feature;
        });
        if (data) {                    
            lstFeatures.splice(lstFeatures.indexOf(data), 1);
        }
    });

    // If the selection is added, push all added selections to array
    changes.added.forEach(function (item) {
        const feature = item.feature;
        lstFeatures.push({
            feature: feature
        });
    });
    zoomToSelectedFeature(aLayer, lstFeatures, aView);
});
Ranga_Tolapi
Frequent Contributor

JeffreyWilkerso Thank you for the response, appreciated.

However, as mentioned, I am looking out for a solution without using the "selection-change" event of FeatureTable?

 

0 Kudos
Ranga_Tolapi
Frequent Contributor

Just noticed this hidden property of FeatureTable. Hope it is okay to rely on this to get the selected rows of FeatureTable.

FeatureTable.grid.selectedItems.items

HeatherGonzago
Esri Contributor

The property is hidden for a reason. You can use it if it works for now, but there is no guarantee that it won't be changed later on. We provided the event to get to the records so that you don't have to do this. I don't know the reasoning for not using this. Perhaps there is a use case that wasn't considered that needs to be, otherwise I would suggest the event as there is no support for undocumented properties, nor a guarantee that they won't change in any upcoming release.

0 Kudos
Ranga_Tolapi
Frequent Contributor

HeatherGonzago I got enlighten, highly appreciated. Fully agree with you.

0 Kudos