Created
September 17, 2014 21:56
-
-
Save vgrem/34b6e126949dfeda908a to your computer and use it in GitHub Desktop.
How to update View using SharePoint 2013 REST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postJson(endpointUri,payload,isUpdate, success, error) | |
{ | |
var headers = {}; | |
headers["Accept"] = "application/json;odata=verbose"; | |
headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val(); | |
if(isUpdate) { | |
headers["X-HTTP-Method"] = "MERGE"; | |
headers["If-Match"] = "*"; | |
} | |
$.ajax({ | |
url: endpointUri, | |
type: "POST", | |
processData: false, | |
data: JSON.stringify(payload), | |
contentType: "application/json;odata=verbose", | |
headers: headers, | |
success: success, | |
error: error | |
}); | |
} | |
function updateView(webUrl,listTitle,viewTitle,viewProperties, success,failure) | |
{ | |
//construct View resource endpoint url | |
var viewUri = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/defaultview"; | |
//prepare View resource paylod | |
var viewPayload = { | |
'__metadata': {'type': 'SP.View'} | |
}; | |
for(var prop in viewProperties){ | |
viewPayload[prop] = viewProperties[prop]; | |
} | |
postJson(viewUri,viewPayload,true, | |
function(data){ | |
success(); | |
}, | |
failure); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can I have an example for viewProperties ?