9

I wrote the following script :-

Get-SPWeb http://vstg01/CustomerPortal/with/
$list = $web.Lists["Meeting"]
$field = $list.Fields["Item Number"]
$field.ShowInNewForm = $False
$field.ShowInEditForm = $False
$field.AllowGridEditing = $False

i want to hide the column from the new, edit & grid editting, but seems i can not modify the AllowGridEditting in this way and i got the following error:-

Property 'AllowGridEditing' cannot be found on this object; make sure it
exists and is settable.
At line:1 char:1
+ $field.AllowGridEditing = $False
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
0

3 Answers 3

7
+50

John

Q: First you need to dig deeper into the field definition using SharePoint Manager 2013, and observe if property 'AllowGridEditing' exists?

A: The property doesn't exist so give PowerShell a break ;)

Why: In SharePoint 2013, client-side rendering (CSR) provides a way to control the output/design of your fields and set of controls by leveraging HTML and JavaScript technologies for example how should the fields render in list views (edit, new or quick edit), search, list forms etc. AllowGridEditing can easily be manipulated CSR technique. I have done a small variation using CSR below.

Now, every field definition comes with JSLink property that can be overridden, by providing your own JS file, which means your own rendering of that field.

Following PowerShell will set up the JSLink property with my own rendering of that field, which eventually hide the field in QuickEdit mode.

PowerShell:

$web = Get-SPWeb "https://yoursite/"
$list = $web.Lists["Meeting"]
$field = $list.Fields["Item Number"]
$field.ShowInNewForm = $False
$field.ShowInEditForm = $False
$field.JSLink = "/_layouts/15/falak/HideQuickEdit.js"
$field.Update();

Here is content of HideQuickEdit.js file, which I have placed under 15 hive. Forgive me for doing it in a quick n dirty way, but you gotta a clean up job to do, like moving JS file to appropriate place, set up the JSLink property in field definitions etc.

P.S. Make sure you have reference to jQuery library in master page.

    function CustomOverrides() {
    var obj = {};
    obj.Templates = {};
    obj.OnPostRender = HideQuickEditValues;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(obj);
}

function HideQuickEditValues(ctx) {
    // hide rendering when in quick edit mode
    if (ctx.inGridMode) {           
        var cell = $("div [name='Item Number']").closest('th'); 
        var cellIndex = cell[0].cellIndex + 1; 
        $('td:nth-child(' + cellIndex + ')').hide(); 
        $('th:nth-child(' + cellIndex + ')').hide(); 
    }   

}
CustomOverrides();

Happy SharePointing.

3

@john You can try setting ReadOnlyField property of the field to True

$field.ReadOnlyField = $True
2

I think AllowGridEditing property is not avaiable but still you can hide it, You can set these values using the object model (likely Powershell, since this is a one off run). The properties of the SPField object are the same (ShowInNewForm / ShowInEditForm).

those you already have in your code. you just need the update at the end.

How to hide a column from new item but not edit item?

5
  • the links you provide talks about hiding in New form not in edit,, while my question is how to prevent the column from being edited using the quick edit grid ?? did you get my point ? and what do you mean exactly by "The properties of the SPField object are the same (ShowInNewForm / ShowInEditForm)." ??
    – John John
    Commented Jun 10, 2015 at 15:18
  • can you adivce more please?
    – John John
    Commented Jun 10, 2015 at 15:23
  • 1
    did you try to set the readonly property msdn.microsoft.com/en-us/library/…
    – Waqas Sarwar MVP
    Commented Jun 10, 2015 at 15:30
  • ok i will try this but for question is can i wrote this directly inside the console, same i do with powershell scripts ? " using (SPSite oSiteCollection = new SPSite("MyServer")) { using (SPWeb oWebsite = oSiteCollection.OpenWeb()) { SPList oList = oWebsite.Lists["MyList"]; SPListItem oItem = oList.Items[0]; oItem.Fields["MyField"].ReadOnlyField = true; oItem.Fields["MyField"].Update(); } }"
    – John John
    Commented Jun 10, 2015 at 15:34
  • second question from my own test setting parameters such as ShowInNewForm & ShowInEditForm will not get saved inside site template. as in my case i am building a site template to be used to create additional sub-sites. but if i set parameters such as ShowInNewForm and i save the subsite as template,, then i create anew subsite based on the templete then all the settings for the ShowInNewForm & ShowInEditForm will be lost..
    – John John
    Commented Jun 10, 2015 at 15:37

Your Answer

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

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