1

I have a field named "Item number" inside my Issue tracking list, which is a system generated ID, and i do not want end users to be able to modify it . now i have set this column as "Hidden" inside the content type to hide it when Create or edit items.

But i am displaying it inside the "All Items" view, which caused a problem, because end users are be able to edit this system generated ID using the Quick Edit capability, as follow:-

enter image description here

so can anyone adivce how to prevent modifying a column using the quick edit capability ?,for example by disabling the related cells ??

EDIT:-

now when i access the site column from my "site setting >> site columns" i got the following URL :-

http://..../_layouts/15/fldedit.aspx?field=ID1&Source=%2F%5Flayouts%2F15%2Fmngfield%2Easpx%3FFilter%3DAll%2520Groups

as follow:-

enter image description here

which means the item id = ID1 is this correct ? based on this i wrote the following HideColumnsINGrid.js script :-

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

then i wrote the following powershell script to define the jslink insdie the column :-

 $web = Get-SPWeb http://vstg01
    $field = $web.Fields["Item Number"]
    $field.JSLink = "Style%20Library/JS/HideColumnsINGrid.js"
    $field.Update($true

)

the power-shell script worked well, but still i i can edit the item named "Item Number" from the quick edit . i have a feeling that the item id and name i specified is not correct

3 Answers 3

1

Is is possible and quite easy to disable field in quick edit mode using client side rendering (a.k.a CSR or JSLink). Here is the sample of doing this http://chuvash.eu/2014/11/28/disabling-a-column-in-quick-edit/

15
  • thanks a lot of the link,, now seems i can hide this <<in the OnPreRender event in our Client Side Rendering (CSR) registration.>> But i am not sure how/where i need to add the script ? is it inside the master page ?
    – John John
    Jun 8, 2015 at 10:48
  • 1
    Try to specify JSLink property in web part properties
    – ECM4D
    Jun 8, 2015 at 11:46
  • 1
    zimmergren.net/technical/… look here how to specify JsLink property
    – ECM4D
    Jun 8, 2015 at 12:58
  • 1
    You can assign your JsLink link directly to the web part, without any SharePoint Designer, as showed in the section "Set the JS Link property on a List View Web Part"
    – ECM4D
    Jun 8, 2015 at 14:55
  • 1
    You can specify JSLINK property for the site column and will work on all lists and view's in site collection. You can specify JsLink property using PowerShell
    – ECM4D
    Jun 8, 2015 at 19:41
0

I believe JQuery & Browser Developer Tools are your options. There might be certain classes/attributes added to the column containing this field in EDIT mode. Just check it.

As per the screenshot, you can blindly get the Column 2 of the editable table & then make it display none or Add a MASK (transparent) around it.

Like in edit mode I found the text that we are editing sits inside a SPAN with class "jsgrid-control-text". So you can say below

  1. Get the SPAN element in SECOND column of each ROW in this table & then add a onChange event handler to it where you say return FALSE
  2. Or using the same above logic hide the COLUMN 2 completely.

You can trigger the above JS function on click of EDIT button. (For which you have to attach a click handler to EDIT button in JQuery.Ready() in your Master page Javascript.

This may not solve or may not be appropriate, but we can get the job done.

2
  • but you are saying that i will always hide the second column, then what if we changed the order of the column inside the view ,, then this will not work !!
    – John John
    Jun 8, 2015 at 10:45
  • you can handle this by looping through all the columns & then find the right one using its attributes & then get the SPAN inside it. Check the below links for custom getting elements with custom attributes matches 1. stackoverflow.com/questions/13392463/…, 2. api.jquery.com/has-attribute-selector Sep 30, 2015 at 6:10
0

If the "Item Number" column is not the built-in ID column, you can just create a calculated column with a formula of =[Item Number] and display that column in your All Items view instead of the actual "Item Number" column. (Depending on how the Item Number is generated by your system, you may have to modify that process slightly to force it to trigger the calculated column's update.) Calculated columns can't be edited in Quick Edit.

If the "Item Number" column is the built-in ID column, it gets a little trickier, because SharePoint will error out when it tries to run the calculation on new items before the ID is generated. In this case, you'll need a more complex approach, with two additional columns and a workflow. For this explanation, I'll use ID to refer to the built-in column.

First, create a text column getID (and make it hidden) and a calculated column showID with the formula =IF(ISBLANK(getID),"",getID)

Then create a workflow set to run on new item creation and manual activation (so you can run it on all your existing items):

If [Current Item:getID] is empty
  Set [Current Item:getID] to [Current Item:ID]

Finally, in your All Items view, display the showID column instead of the ID column, and run the workflow on all of your existing list items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.