I am attempting to sort my Search widget's suggestionTemplate's return in ascending order. The widget is looking at 4 fields all in a single feature class. This is an employee locator app and the Search fields in this feature class are for Employee Name, Room, Office Phone, and Cell phone. Using orderByFields for Employee Name technically works but if a room is empty (Null value for Employee Name) it is now at the top of the return. I am looking to have occupied rooms return first and then empty rooms. Basically Null values for Employee Name at the bottom of the suggestions.
Hope I explained it coherently. I've been working with ESRI support but they haven't found a solution.
This post is connected to my previous one: https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-null-values-from-the-searc...
@JoelBennett thanks again for solving that one!
Here is my code for the Search widget:
Solved! Go to Solution.
Ok, so the problem here is that the response of the query is in a binary (pbf) format, not JSON. There are a couple ways to deal with this, and I would recommend starting with the easiest, which is to force the queries to use JSON format, and not pbf. To do that, add the following somewhere before the SDK is loaded:
<script type="text/javascript">
window.dojoConfig = {
has: {
"featurelayer-pbf": false
}
};
</script>
If you already have a dojoConfig object, you can consolidate the above with that.
It seems that if you added an "after" function to your interceptor, you could use it to adjust the order as desired:
esriConfig.request.interceptors.push({
urls: /\/query/,
before({ requestOptions }) {
if (/LIKE '[^%]/g.test(requestOptions.query?.where)) {
('like request intercepted', requestOptions);
requestOptions.query.where = requestOptions.query.where.replace(/ LIKE \'/g, ' LIKE \'%');
}
},
after: function(response) {
var notNulls = [];
var nulls = [];
response.data.features.forEach(function(feature) {
if (feature.attributes.KNOWNAS === null)
nulls.push(feature);
else
notNulls.push(feature);
});
response.data.features = notNulls.concat(nulls);
}
})
Thanks Joel,
Unfortunately when we implemented your code our layers no longer displayed in our app and the Search widget didn't return anything. The only error that was returned was in the Chrome Developer's tool
Here is how we added the code:
Ok, so the problem here is that the response of the query is in a binary (pbf) format, not JSON. There are a couple ways to deal with this, and I would recommend starting with the easiest, which is to force the queries to use JSON format, and not pbf. To do that, add the following somewhere before the SDK is loaded:
<script type="text/javascript">
window.dojoConfig = {
has: {
"featurelayer-pbf": false
}
};
</script>
If you already have a dojoConfig object, you can consolidate the above with that.
Thanks Joel, you did it again! Thank you so much.