This blog helps you to remove the unwanted columns in SharePoint 2013, using the JavaScript Object Model (JSOM).
#######################################
# Delete columns in SharePoint 2013 List View Using JSOMO365
# Applies To: SharePoint 2013,JSOM,List,Office 365
# Author: Gowtham Rajamanickam
# Date:18-March-2017
#Version:1.0
########################################
- <scrtipt>
-
- updateListView('Documents','All Documents',fieldsToHide, printViewInfo,logError);
-
- var listTitle='Documents';
- var viewTitle='CustomView';
- var arrayoffieldsToHide=['Title','Tutorial','Test'];
- ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js");
-
- function updateListView() {
- var context = SP.ClientContext.get_current();
- var web = context.get_web();
- var list = web.get_lists().getByTitle(listTitle);
- var view = list.get_views().getByTitle(viewTitle);
- var fieldNames = view.get_viewFields();
-
- context.load(view);
- context.load(fieldNames);
- context.executeQueryAsync(
- function(){
- for(var i = 0; i < fieldNames.get_count();i++) {
- var fName = fieldNames.getItemAtIndex(i);
- var found = $.inArray(fName, fieldsToHide) > -1;
- if(found) {
- fieldNames.remove(fName);
- }
- }
- view.update();
- context.executeQueryAsync(success,error);
- },
- error
- );
- }
-
-
- </scrtipt>
Execute the code given above, check your SharePoint site and columns are removed successfully or not.
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 I’ll use your feedback to double-check the facts, add info and update this blog.