0

Is it possible to use the "ShowInGrid=True" element of the URL to act as a trigger for show/hiding a field in a datasheet view?

The below code that will hide it nicely on the default allitems view but i would like that to be field to be visible on the quickedit view.

(function () {

function RemoveFields(ctx) {
    var fieldName = "Date"; // here Date is field or column name to be hide
    var header = document.querySelectorAll("[displayname=" + fieldName + "]")[0].parentNode;
    var index = [].slice.call(header.parentNode.children).indexOf(header) + 1;
    header.style.display = "none";
    for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) {
        cells[i].style.display = "none";
    }
}

function registerRenderer() {
    var ctxForm = {};
    ctxForm.Templates = {};
    ctxForm.OnPostRender = RemoveFields;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');

(Source https://riptutorial.com/sharepoint/example/26699/hide-column-from-sharepoint-list-view-using-csr-)

If hiding is not an option can the field be obfuscated/md5'd instead on the list view?

I can see how other examples on the non quick edit views will work by highlighting the form and using the ("NewForm": hideField) notation (from Dylan Christy) but getting it to appear for quick edit is causing me problems

Thanks in advance

0

So I eventually got it working

In the end it was pretty simple but still took some figuring out credit goes to avishnyakov and the SPDev codeplex site

Hope this helps someone

(function () 
{
   function ClientNameToggle(ctx) 
 {var fieldName = "ClientName"; // here Date is field or column name to be hide
var header = document.querySelectorAll("[name=" + fieldName + "]")[0].parentNode;
    var index = [].slice.call(header.parentNode.children).indexOf(header) + 1;

    if(ctx.inGridMode === true)
{
    header.style.display = "table-cell";

        for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) 
    {
            cells[i].style.display = "table-cell";
    }
}
else 
{
    header.style.display = "none";

        for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) 
    {
            cells[i].style.display = "none";
    }
    }

}

function registerRenderer() 
{
    var ctxForm = {};
    ctxForm.Templates = {};
    ctxForm.OnPostRender = ClientNameToggle;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}

ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');

})();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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