Select to view content in your preferred language

How to filter data on arcgis layer in Javascript

5358
8
Jump to solution
06-06-2017 08:24 PM
KamalMittal
Deactivated User

Hi,

 I want to filter data on feature layer when user select value from dropdown.

On my feature layer, I have showed 25 locations with a pin symbol and there is dropdown which contains all these 25 locations. Now what I want is when user select value from dropdown then map will show and zoomin that location only  and rest of the locations will disappear. So how do I achieve that?

Thanks,

Kamal

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Kamal,

   When the user selects from the dropdown you apply a definitionexpression to the layer.

https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#setdefinitionexpression 

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Kamal,

   When the user selects from the dropdown you apply a definitionexpression to the layer.

https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#setdefinitionexpression 

KamalMittal
Deactivated User

Thanks Robert for your reply.  

Here setDefinitionExpression taking exact data to search but I want to search based on substring. Can we achieve that thing?

Thanks,

Kamal

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kamal,

   Not sure what you mean. If the user selects an item from the drop down do you not know the exact value?...

0 Kudos
KamalMittal
Deactivated User

Yes, with dropdown there is also textbox for searching. When user type into textbox then I want to search from textbox value also.

Thanks,

Kamal

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kamal,

   Then you just formulate your SQL String for the defintion expression from the textbox input (i.e. "field1 LIKE '%" + textbox.value + "'")

0 Kudos
KamalMittal
Deactivated User

Thanks Robert. Below is the code which i am using but searching is not working:

featureLayer.setDefinitionExpression("street_name LIKE % 'ORCHARD'");

Here street_name is field and ORCHARD is the textbox value.

Can you please confirm that is SQL string is correct ?

Thanks,

Kamal

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kamal,

  No the correct code would be:

featureLayer.setDefinitionExpression("street_name LIKE '%ORCHARD%'");

KamalMittal
Deactivated User

Thanks Robert. 

0 Kudos