How to make single selection on a FeatureTable

2615
6
Jump to solution
05-14-2021 11:24 AM
ShaningYu
Frequent Contributor

Refer to https://developers.arcgis.com/javascript/latest/sample-code/widgets-featuretable-map/, I loaded ESRI's FeatureTable widge into my App.  Is it possible to make single record selection rather than multiple records selection?  I mean that if clicking a record, the previous selected record should be checked off.  Thanks.

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor
0 Kudos
6 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

 

Yes it is possible. Just call FeatureTable.clearSelection() method right before you call FeatureTable.selectRows() method. 

 

I modified an SDK sample for this. 

Hope this helps,

-Undral

0 Kudos
ShaningYu
Frequent Contributor

Undral:  Thanks for your response.  Actually, I did have used the code 

myTable.on('selection-change', (event) => {
myTable.clearSelection();
event.added.forEach(function (item) { ...

It does clear the selection.  However, the new-clicked row's check-on also becomes off.  I wonder if there is away to keep the new-clicked row checked-on.

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Please take a look at the test app provided above. You must clear the selection right before you call FeatureTable.selectRows() method not in response to the event. 

In the test app this is how the clearSelection is called. 

 featureTable.clearSelection();
 candidate && featureTable.selectRows(candidate.graphic);
0 Kudos
ShaningYu
Frequent Contributor

Thanks for your response.  After adding

featureTable.selectRows(candidate.graphic);

got error   candidate  not defined.  Could you guide me how to define the variable?  Thanks.

0 Kudos
UndralBatsukh
Esri Regular Contributor

It is in the app I provided.  Please take a look at the app and modify it to meet your needs. https://codepen.io/U_B_U/pen/rNyeRPL?editors=100

0 Kudos
ShaningYu
Frequent Contributor

Your approach is right.  Since my code is different somehow, I can't use yours directly till I revise my code somehow.  However, I will accept yours as the solution.  Thanks a lot.

0 Kudos