4

I can get the return list from this query, but if I add the orderby syntax, it just ignores it (no error, just doesn't sort the return set).

http://<mysite>/_vti_bin/listdata.svc/Products?$filter=DeliveryFormat eq true&$orderby=Title desc
Robert Lindgren
  • 24,520
  • 12
  • 53
  • 79
April Drake
  • 1,095
  • 6
  • 32
  • 62

1 Answers1

1

It depends on where you are reviewing the results.

If you're building the URL in the address bar of a browser, the results WILL NOT necessarily be sorted by the orderby parameter. That is because the "Displaying" section on the right side of the Atom feed results, in the browser, takes over. You can actually sort it right there on the screen by clicking the column labels under the "Sort by:" section.

However, if you submit the request via ajax or something in code and inspect the returned JSON, you will see that the results ARE sorted properly.

Results from my test, look for: "Title":"test 1" & "Title":"test 2" :

Test 1 - asc

LOG (url): //_vti_bin/ListData.svc/MD_App?$select=Id,Title,ModifiedBy,Modified&$orderby=Title asc

LOG (json): {"d":{"results":[{"__metadata":{"uri":"http:///_vti_bin/ListData.svc/MD_App(1)","etag":"W/\"1\"","type":"Microsoft.SharePoint.DataService.MD_AppItem"},"Id":1,"Title":"test 1","Modified":"2015-08-20T09:17:07.000Z","ModifiedBy":{"__deferred":{"uri":"http:///_vti_bin/ListData.svc/MD_App(1)/ModifiedBy"}}},{"__metadata":{"uri":"http:///_vti_bin/ListData.svc/MD_App(2)","etag":"W/\"1\"","type":"Microsoft.SharePoint.DataService.MD_AppItem"},"Id":2,"Title":"test 2","Modified":"2015-08-20T09:17:14.000Z","ModifiedBy":{"__deferred":{"uri":"http:///_vti_bin/ListData.svc/MD_App(2)/ModifiedBy"}}}]}}

Test 2 - desc

LOG (url): //_vti_bin/ListData.svc/MD_App?$select=Id,Title,ModifiedBy,Modified&$orderby=Title desc

LOG (json): {"d":{"results":[{"__metadata":{"uri":"http:///_vti_bin/ListData.svc/MD_App(2)","etag":"W/\"1\"","type":"Microsoft.SharePoint.DataService.MD_AppItem"},"Id":2,"Title":"test 2","Modified":"2015-08-20T09:17:14.000Z","ModifiedBy":{"__deferred":{"uri":"http:///_vti_bin/ListData.svc/MD_App(2)/ModifiedBy"}}},{"__metadata":{"uri":"http:///_vti_bin/ListData.svc/MD_App(1)","etag":"W/\"1\"","type":"Microsoft.SharePoint.DataService.MD_AppItem"},"Id":1,"Title":"test 1","Modified":"2015-08-20T09:17:07.000Z","ModifiedBy":{"__deferred":{"uri":"http:///_vti_bin/ListData.svc/MD_App(1)/ModifiedBy"}}}]}}

Test 3

To test in the browser, add this to the end of the URL: &$top=1

The following URL returns "Test 1":

//_vti_bin/ListData.svc/MD_App?$select=Id,Title,ModifiedBy,Modified&$orderby=Title asc&$top=1

While this one returns "Test 2":

//_vti_bin/ListData.svc/MD_App?$select=Id,Title,ModifiedBy,Modified&$orderby=Title desc&$top=1

WhiteHat
  • 161
  • 10