CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

Disabling a column in Quick Edit

jsgrid-015
In my project I have a column called Request Status. This column is not shown in any forms, meaning users should not edit, because it is controlled through the app. Nevertheless it is editable in the Quick Edit.

Yesterday I wrote about jsgrid in my blog. Now comes more. Today I’ll share a little practical solution how one can disable editing a field in Quick Edit.

The field is edited in jsgrid, but to disable it, we only have set the property called AllowGridEditing to false on our column (not even touching the heavy jsgrid api). We can do in the OnPreRender event in our Client Side Rendering (CSR) registration. Having the context object we have access to the Fields (ContextInfo.ListSchema.Field):

(function () {
    var overrideContext = {};
    overrideContext.Templates = overrideContext.Templates || {};
    overrideContext.Templates.OnPreRender = function(ctx) {
    	var statusField = ctx.ListSchema.Field.filter(function(f) {
    		return f.Name === 'Request_x0020_Status';
    	});
    	if (statusField) {
    		statusField[0].AllowGridEditing = false;
    	}
    }
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
})();

Another way is to implement the display form:

(function () {
    var view = function (ctx, field) {
        if (ctx.inGridMode) {
            field.AllowGridEditing = false;
        }
        return window.RenderFieldValueDefault(ctx);
    };
    var overrideContext = {};
    overrideContext.Templates = overrideContext.Templates || {};
    overrideContext.Templates.Fields = {
        'Request_x0020_Status': {
            'View': view
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
})();

21 responses to “Disabling a column in Quick Edit

  1. Niki 2014-12-14 at 17:41

    Hi!

    Thanks for sharing this script, very usefull.
    My question is, how can I set the DefaultValue in the DataGrid with same field where I set AllowGridEtditing to false?

    Thanks,
    Niki

    • Anatoly Mironov 2014-12-18 at 09:41

      You can try this:

      return window.RenderFieldValueDefault(ctx);
      

      But in some cases it doesn’t work. Then you need to return the field value:

      return ctx.CurrentItem[ctx.CurrentFieldSchema.Name] || '';
      
  2. RP 2015-05-19 at 09:25

    Hi, Thanks for nice stuff , I want to enable editing for new item for existing item i want to disable editing your code disabled fully.plz help

  3. Pingback: Disable a site collection column inside lists's quick edit grid | Question and Answer

  4. wasif 2015-08-24 at 14:26

    how can i set AllowGridEditing to false for multiple columns ?

  5. Renuka 2015-11-05 at 07:41

    Hi, can you please help me to set “AllowGridEditing” to false for multiple columns? I tried repeating the code for “Request Status”, but it doesn’t seem to work.

  6. Renuka 2015-11-05 at 12:12

    Please help me with multiple column disabling with jslink in quick edit

  7. VJ 2015-12-07 at 23:37

    Hi
    Thanks for the help ful post, I am trying to sort values in multi choice field in quick edit, can you please help, I tried to write function to sort but it doesn’t apply to values in the columns

  8. Drew Griffin 2015-12-28 at 22:53

    Is this script inserted in a CEWP above the quick edit web part or is it inserted somewhere else into existing code using SharePoint Designer? Or other method. Thanks for your help.

  9. Pingback: SharePoint 2013 – Disable multiple columns in Quick Edit | Why Didn't I Think of That?

    • Anatoly Mironov 2016-02-02 at 17:23

      Great! Thanks for sharing! Now your blog post will be linked. I read your blog. Good stuff. Keep posting!

    • Jan Marek 2016-02-10 at 10:40

      Hi, thanx for this. But it didn´t quite work for me. This is what I loaded as a text file into the documents library (library has check out required). I assigned rights for that file just for me (the list views were created by others as public views but I have site collection admin rights on that SP site and placed the URL into CEWP in that view and clicked stop Editing. So here is the code I used

      var updateViewerFields=[“Actual Completion Date”,”Date of Update”,
      “Start Date”];
      (function updateView() {
      var overrideContext = {};
      overrideContext.Templates = overrideContext.Templates || {};
      overrideContext.Templates.OnPreRender = function(ctx) {

      for(j=0; j<ctx.ListSchema.Field.length; j++)
      {
      var f = ctx.ListSchema.Field[j];
      for(i=0;i<updateViewerFields.length;i++){
      if(f.DisplayName == updateViewerFields[i]){
      f.AllowGridEditing=false;
      }
      }
      }
      }
      SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
      })();

      but the columns are still editable.
      Any thoughts please?
      Many thanx again

      • Anatoly Mironov 2016-02-11 at 07:28

        You have to overrride the “View” behaviour of the fields. f.AllowGridEditing outside “View” override will not affect the field.

  10. JV 2016-06-03 at 15:59

    Why not just use a calculated column? What I did was to create and set a calculated column to equal the value of the column I wanted to disable. Then I added the calculated column to the view of the Quick Edit. Calculated columns are not editable.

  11. Chris Hernandez 2016-08-13 at 16:54

    Dear Anatoly, do you know how I can disable bulk edit in datasheet/quick edit view?

    Chris🤔

  12. Farhan Aslam 2017-05-04 at 08:56

    Thanks

  13. Saurabh shankar 2017-06-22 at 18:46

    Hi Anatoly
    I am trying to implement a scenario in which I want to restrict the users to select the choice options present with choice field in Quick edit more. For eg.- choice contains month names – Jan, Feb, March, Apr etc.. I want them to have only month options which is next three months.

    Any help is appreciated.

  14. SShankar 2017-06-22 at 18:47

    Hi Anatoly
    I am trying to implement a scenario in which I want to restrict the users to select the choice options present with choice field in Quick edit more. For eg.- choice contains month names – Jan, Feb, March, Apr etc.. I want them to have only month options which is next three months.

    Any help is appreciated.

Leave a Reply to Saurabh shankar Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Architect, Speaker, Author

Microsoft 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Cameron Dwyer

Office 365, SharePoint, Azure, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

DevOps, Cloud and Blockchain Consultant

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know about SharePoint - CommunicoCuspis

SharePointDiver

SharePoint på ren svenska

%d bloggers like this: