Having some issues with orderByFields on my data set. I've tried both through URL params and via code and both seem to just return the same results without ordering the data with the selected field. I'm using the following code:
var n = '' ;
var xz = '"TRUE" = "TRUE"';
var szn = '["Subdivision ASC"]';
return p.outFields = n, p.where = xz, p.orderByField = szn, p.returnGeometry = !o, o && c.setRequestPreCallback(e.requestPreCallback), f.execute(p).then(function(e) {
return e.features ? e.features : []
}, function(e) {
return []
})
});
I have also tried via adding parameters via the URL like :
https://{ServerURL}/0/query?where=Acres>0.1&orderByFields=Subdivision+ASC
Supports Advanced Queries is True as is Supports Order By. Current Version is 10.51.
Any suggestions?
Spark,
Your issue is this
var szn = '["Subdivision ASC"]';
is considered a string and not an array which is what the Query is expecting
Change to
var n = ['*'];
var xz = '1=1';
var szn = ["Subdivision ASC"];
Unfortunately, I've tried that way as well. I just tried it again and it seems to have no effect on the actual query. I've also tried it with a few different fields and the order that everything displayed doesn't change.
Spark,
I am not sure what is going wrong on your end then. I can get Order By to work in code on my end. Is the fact that your code minified/uglified mean you are attempting to editi the APIs internal code directly?
I've actually been handed the site by another person, and I had to de-minify the js to make it slightly readable, so I'm not entirely sure something else somewhere in the code isn't overriding the sort. The sort works in the query builder, but pulling that URL into my application or trying to add the orderbyfields to the javascript just seems to continue to get ignored. Thanks for trying!
I was running into this not working because I made the same typo you have above. No exception was thrown...
You have (and I had)
query.orderByField = <your_field>;
but the doc has
query.orderByFields = [ <your_field> ];