Introduction
Sometimes, we get the requirement to allow users to do bulk updates on list items but want to restrict this to updating/editing a few of the columns. We can't do this by default in SharePoint.
Solution
We need to use custom Javascript and inject it on a particular view of the list to protect the columns. Use the below script to add it on a quick edit view to protect columns.
- < script type = "text/javascript" >
-
-
- var updateViewerFields = ["Title", "Status"];
- (function updateView() {
- var currContext = {};
- currContext.Templates = currContext.Templates || {};
- currContext.Templates.OnPreRender = function(ctx) {
- for (j = 0; j < ctx.ListSchema.Field.length; j++) {
- var listSchema = ctx.ListSchema.Field[j];
- for (i = 0; i < updateViewerFields.length; i++) {
- if (listSchema.DisplayName == updateViewerFields[i]) {
- listSchema.AllowGridEditing = false;
- }
- }
- }
- }
- SPClientTemplates.TemplateManager.RegisterTemplateOverrides(currContext);
- })();
- < /script>
Save this script to a txt file and upload it in the site assets folder in SharePoint.
Add a content editor web part to a quick edit list view page and refer to the file and save the page.
Outcome
Defined columns in the script will be protected from editing in datasheet/quick edit view.
In my example here, I want to protect Title and Status column so I added only those columns in array but you can add as many as columns to this array object as you like.
Note
I have tested this on an SP 2013 environment.