Delete Columns In SharePoint 2013 List View Using JSOM

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 
######################################## 
  1. <scrtipt>  
  2.   
  3. updateListView('Documents','All Documents',fieldsToHide, printViewInfo,logError);  
  4.   
  5. var listTitle='Documents';  
  6. var viewTitle='CustomView';  
  7. var arrayoffieldsToHide=['Title','Tutorial','Test'];  
  8. ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js");  
  9.   
  10. function updateListView() {  
  11.     var context = SP.ClientContext.get_current();  
  12.     var web = context.get_web();  
  13.     var list = web.get_lists().getByTitle(listTitle);  
  14.     var view = list.get_views().getByTitle(viewTitle);  
  15.     var fieldNames = view.get_viewFields();  
  16.   
  17.     context.load(view);  
  18.     context.load(fieldNames);  
  19.     context.executeQueryAsync(  
  20.         function(){  
  21.             for(var i = 0; i < fieldNames.get_count();i++) {  
  22.                 var fName = fieldNames.getItemAtIndex(i);  
  23.                 var found = $.inArray(fName, fieldsToHide) > -1;  
  24.                 if(found) {  
  25.                    fieldNames.remove(fName);   
  26.                 }  
  27.             }  
  28.             view.update();   
  29.             context.executeQueryAsync(success,error);  
  30.         },   
  31.         error  
  32.     );  
  33. }  
  34.   
  35.   
  36. </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.