Forum Discussion
How do you reorder columns of a Sharepoint list when using the API?
When using the Sharepoint API to return a list we display the columns in the order they are sent to us from Sharepoint. How can the user change the order in Sharepoint so that the response returned from the API will order the columns the same? Currently reordering the columns in Sharepoint has no affect on the column ordering returned in the API. Also, if you change the ordering of the columns in the list and then save that reordered list to a new view, the column ordering is not preserved for the new view when calling from the Sharepoint API.
Here is sample list.
Response envelope in Fiddler and you see Column1 and Column 2 are returned in the order the columns were originally created in the list:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data ItemCount="1">
<z:row ows_ID='1' ows_ContentType='Item' ows_Title='test' ows_Modified='2022-04-13 07:10:29' ows_Created='2022-04-13 07:10:29' ows_Author='6;#Bobby Williams' ows_Editor='6;#Bobby Williams' ows__UIVersionString='1.0' ows_Attachments='0' ows_LinkTitleNoMenu='test' ows_LinkTitle='test' ows_ItemChildCount='1;#0' ows_FolderChildCount='1;#0' ows__ComplianceFlags='1;#' ows__ComplianceTag='1;#' ows__ComplianceTagWrittenTime='1;#' ows__ComplianceTagUserId='1;#' ows_Column1='test' ows_Column2='test' ows__ModerationStatus='0' ows__Level='1' ows_UniqueId='1;#{2B04BBAC-8D99-417B-BA9B-0BAD24138BAA}' ows_FSObjType='1;#0' ows_Created_x0020_Date='1;#2022-04-13 07:10:29' ows_MetaInfo='1;#' ows_owshiddenversion='1' ows_FileLeafRef='1;#1_.000' ows_PermMask='0x7ffffffffffbffff' ows_ScopeId='1;#{2E7B7DCF-3269-4E64-A684-628BCDE97B65}' ows_FileRef='1;#sites/BobbysTestSite/Lists/TestColumnOrdering/1_.000' />
</rs:data>
</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>
I then edited the list to reorder Column1 and Column2 so they are reversed:
The view now looks like this:
Column1 and Column2 are reversed in the view.
Now capturing the response envelope in Fiddler looks the same. The column ordering is still Column1 then Column2.:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data ItemCount="1">
<z:row ows_ID='1' ows_ContentType='Item' ows_Title='test' ows_Modified='2022-04-13 07:10:29' ows_Created='2022-04-13 07:10:29' ows_Author='6;#Bobby Williams' ows_Editor='6;#Bobby Williams' ows__UIVersionString='1.0' ows_Attachments='0' ows_LinkTitleNoMenu='test' ows_LinkTitle='test' ows_ItemChildCount='1;#0' ows_FolderChildCount='1;#0' ows__ComplianceFlags='1;#' ows__ComplianceTag='1;#' ows__ComplianceTagWrittenTime='1;#' ows__ComplianceTagUserId='1;#' ows_Column1='test' ows_Column2='test' ows__ModerationStatus='0' ows__Level='1' ows_UniqueId='1;#{2B04BBAC-8D99-417B-BA9B-0BAD24138BAA}' ows_FSObjType='1;#0' ows_Created_x0020_Date='1;#2022-04-13 07:10:29' ows_MetaInfo='1;#' ows_owshiddenversion='1' ows_FileLeafRef='1;#1_.000' ows_PermMask='0x7ffffffffffbffff' ows_ScopeId='1;#{2E7B7DCF-3269-4E64-A684-628BCDE97B65}' ows_FileRef='1;#sites/BobbysTestSite/Lists/TestColumnOrdering/1_.000' />
</rs:data>
</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>
What’s the point of defining a Columns order if it doesn't work in the API as well?
Next I tried saving this reordered list as a view:
Open the "Edit View" confirms the view was created with the columns reversed in the order we would like to see them returned in the API:
The response from the api for this view is shown here and still the columns are returned in the original order the columns were added to the original list.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<rs:data ItemCount="1">
<z:row ows_ID='1' ows_ContentType='Item' ows_Title='test' ows_Modified='2022-04-13 07:10:29' ows_Created='2022-04-13 07:10:29' ows_Author='6;#Bobby Williams' ows_Editor='6;#Bobby Williams' ows__UIVersionString='1.0' ows_Attachments='0' ows_LinkTitleNoMenu='test' ows_LinkTitle='test' ows_ItemChildCount='1;#0' ows_FolderChildCount='1;#0' ows__ComplianceFlags='1;#' ows__ComplianceTag='1;#' ows__ComplianceTagWrittenTime='1;#' ows__ComplianceTagUserId='1;#' ows_Column1='test' ows_Column2='test' ows__ModerationStatus='0' ows__Level='1' ows_UniqueId='1;#{2B04BBAC-8D99-417B-BA9B-0BAD24138BAA}' ows_FSObjType='1;#0' ows_Created_x0020_Date='1;#2022-04-13 07:10:29' ows_MetaInfo='1;#' ows_owshiddenversion='1' ows_FileLeafRef='1;#1_.000' ows_PermMask='0x7ffffffffffbffff' ows_ScopeId='1;#{2E7B7DCF-3269-4E64-A684-628BCDE97B65}' ows_FileRef='1;#sites/BobbysTestSite/Lists/TestColumnOrdering/1_.000' />
</rs:data>
</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>
How can the Sharepoint customer order their lists so that the results in the call to the API are in the order they want them returned?
Thanks in advance.