disable the column based on another column value in datasheet view in sharepoint list

ameneh maleki 46 Reputation points
2025-01-20T10:32:21.4866667+00:00

Hi

I used below code to disable some columns in datasheet view in allitems.aspx in sharepoint list:

<script>

var updateViewerFields=[“column1”,”column2”,”column3”];

(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=true;

             }

          }

       }

    }

 SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);

 })();

</script>

Now I want to change this javascript code to disable column2, when column1 for example equals to “test”.

How I can do this?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,172 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,035 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 21,165 Reputation points Microsoft Vendor
    2025-01-21T05:14:42.7933333+00:00

    Hi @ameneh maleki,

    Thanks for reaching out to us. We are very pleased to support you.

    According to the information you provided and the research I have done, I may understand that you want to disable Column2 in the view (display or edit?) based on the value of Column1. If there is anything wrong, please correct me.

    If there is not anything wrong, it is sorry to say that we can't disable another column (display or edit) in the view based on the value of one column. The smallest unit of operation in SharePoint list view is column, which means we can only disable a whole column.

    We would like to make sincere apology for the inconvenience caused. Meanwhile, it is proposed that you can vote your feedback via this link. With higher feedback like this, MS will take this into serious account and make some modifications accordingly, which will benefit more community members.

    Thanks for your meaningful contributions.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. It will be beneficial to more community members reading here. Your contribution will be highly appreciated.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.