Question

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
Was it helpful?

Solution

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.

OTHER TIPS

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

$field.ReadOnlyField = $True

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top