1

So the below function, gets data from a list in a certain order - by SortOrder column. If i go to the url in my browser and run it the order is as expected, however the output (JSON) seems to then revert to the order by ID (it seems to use the ID as the key) - any ideas or suggestions what I can do?

private _getListData(listName: string): Promise<ISPLists> {

const queryString: string = '$select=Title,ID,Created,Author/ID,Author/Title&$expand=Author/ID,Author/Title&$Orderby=SortOrder';

return this.context.spHttpClient
  .get(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('${listName}')/items`,//?${queryString}`,
  SPHttpClient.configurations.v1)
  .then((response: SPHttpClientResponse) => {
    if (response.status === 404) {
      Log.error('js-display-List', new Error('List not found.'));
      return [];
    }else {
      return response.json();
    }
  });
 }
  • Is the column "sortOrder" or "SortOrder"? odata is generally case sensitive. – Mike Smith - MCT - MVP May 25 '18 at 14:57
  • sorry it is SortOrder - that part is correct and returning as expected. Its the JSON output that then changes the order – Jason May 25 '18 at 15:04
  • I created a similar setup to test your query, and I did not see any sort issues. Is the "SortOrder" column in the top level list? – Mike Smith - MCT - MVP May 26 '18 at 19:15
  • What are the backticks for? (`) – Mike Smith - MCT - MVP May 26 '18 at 19:16
  • Just to confirm the sort issues only appear when returning as json - I think this may be by design with JSON though after some further research. – Jason May 29 '18 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.