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
Solved! Go to Solution.
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
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
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
Kamal,
Not sure what you mean. If the user selects an item from the drop down do you not know the exact value?...
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
Kamal,
Then you just formulate your SQL String for the defintion expression from the textbox input (i.e. "field1 LIKE '%" + textbox.value + "'")
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
Kamal,
No the correct code would be:
featureLayer.setDefinitionExpression("street_name LIKE '%ORCHARD%'");
Thanks Robert.