This blog helps you to change the view in SharePoint 2013, using REST API. The business process is evolving and the users want to see the additional fields in the default view. I was able to add the necessary columns via content type. Now, I need to change the default view (all have the same name) to assist the users in sorting and filtering the files.
- #######################################
- # Change the View Using REST API in SharePoint 2013
- # Applies To: SharePoint 2013,JSOM,List,Office 365
- # Author: Gowtham Rajamanickam
- # Date:18-March-2017
- #Version:1.0
-
- ########################################
- var newView='CustomView';
- var ListName='TutorialList';
- var defaultView='All Items';
-
- (function () {
- var payload = "{'__metadata': {'type': 'SP.View'}, 'Title': newView}";
- var xRequestDigest = $("#__REQUESTDIGEST").val();
- console.log(payload);
- console.log(xRequestDigest);
- $.ajax({
- url: "WEBSITE-URL/_api/web/lists/getbytitle(ListName)/views/getbytitle(defaultView)",
- method: "POST",
- data: payload,
- headers: {
- "content-type": "application/json;odata=verbose",
- "X-Requestdigest": xRequestDigest,
- "accept": "application/json; odata=verbose",
- "X-HTTP-Method": "MERGE"
- },
- success: printInfo,
- error: logError
- });
- })()
-
- function printInfo() {
- console.log('View Updated');
- }
-
- function logError(error) {
- console.log(JSON.stringify(error));
- }
-
Execute this code and check your SharePoint site and columns, which are removed successfully.
Was my blog helpful?
If so, please let us know at the bottom of this page. If not, let us know what was confusing or missing and I’ll use your feedback to double-check the facts, add info and update this blog.