Removing Thousand Separator from Search Widget Results in ArcGIS JS API

144
2
2 weeks ago
PixelPioneer
New Contributor

Hello,

I am currently working on a TypeScript React project using the ArcGIS JS API (version 4.x). I have encountered an issue with the Search Widget where I need to remove the thousand separator in the query results.

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html

Currently, the Search Widget automatically formats numbers with thousand separators, but for our application requirements, this formatting needs to be removed. I have explored the documentation and settings but couldn't find a direct way to achieve this.

Could anyone provide guidance or a workaround to customize the Search Widget to remove the thousand separator from the search query results?

Thank you and Best regards

0 Kudos
2 Replies
AndreV
by
Occasional Contributor

Here's our solution for formatting the suggestions in the search widget (we removed the federal state):

	const widget = new Search(props);

	widget.on("suggest-complete", (ev) => {
		ev.results[0].results.forEach((res) => {
                        // remove federal state
			res.text = res.text.replace(", Baden-Württemberg, DEU", "");
		});
	});

 

gdi-hohenlohekreis.de
0 Kudos
ClintonLunnUGS
New Contributor

Are you wanting to remove the thousand separator from the suggestion? I had a similar requirement (needed title case in the suggestions instead of all caps), so i ended up making a custom search source. That gives you control over the formatting of what gets displayed to you.

https://developers.arcgis.com/javascript/latest/sample-code/widgets-search-customsource/

that sample got me started. I'm not sure which approach would be better (compared to the event listener for "suggest-complete" but the custom source approach would mean you don't have to have that global event listener placed in some useEffect somewhere in your code, but can define that behavior when you configure the search widget. 

0 Kudos