Hi,
I want to sort the search result(SuggestResult) with the Api 4 and the "esri/widgets/Search "!
The featureservice allows you to sort:
The Advanced Query Capabilities:
The standard sort is the objectid!
Where do I specify orderByFields: ["key","hsn","hsn_zusatz"]?
var searchWidget = new Search({
view: view,
allPlaceholder: "Search for",
searchAllEnabled: false,
includeDefaultSources: false,
sources:[{
featureLayer:{
url:"XXX/Search_HSN/FeatureServer/1",
popupTemplate: {
title: "Adresse: {strasse_hsn}",
overwriteActions: false,
},
},
//orderByFields: ["key_alb","hsn","hsn_zusatz"], ?????? where
searchFields: ["strasse_hsn"],
displayField: "strasse_hsn",
outfields: ["*"],
exactMatch: false,
name: "Street & number.",
placeholder: "Search for",
minSuggestCharacters: 0,
suggestionsEnabled: true,
maxSuggestions: 20,
resultSymbol: {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "circle",
color: [161,14,210,0.5],
size: "20px", // pixels
outline: { // autocasts as new SimpleLineSymbol()
color: [161,14,210,0.5],
width: 1 // points
}
}
},
Hi Ulrich,
orderByFields is available in Query not in Search. Here is the webhelp:
Query | API Reference | ArcGIS API for JavaScript 4.10
I have a sample code for your reference:
You need to wire it into the suggest-complete even handler for the widget (because why do common sense things in your developement?):
searchWidget.on("suggest-complete", function (evt) {
searchWidget.suggestions.forEach(function (item) {
//I have a lot of features with the same name and unique identifier we generated, but different Object IDs. To keep the list short, I'm filtering it to only have one occurrence of each name
let temp = [];
//For each set of results for each layer searched, check to see if you've already found a feature with the same display name
item.results.forEach(function (entry) {
if (!temp.some(function (nextItem) {
return nextItem.text == entry.text
})) temp.push(entry);
});//end of 2nd forEach
//Take the results and sort the list
temp.sort(function (a, b) {
return a.text.localeCompare(b.text);
});//end of sort function
//Assign the sorted array back to the results attribute.
item.results = temp;
});//end of forEach
});
Hi, can you sort the 4.14 js api search widget to display exact matches first?
Thanks,
Shane
I have same issue as described by Shane above