Hide Column Archives : Binary Bits https://blog.binarybits.net/tag/hide-column/ Bits & Pieces - A blog by Kannan Balasubramanian Fri, 01 Dec 2017 06:27:47 +0000 en-GB hourly 1 https://wordpress.org/?v=6.5.2 Hide SharePoint list column https://blog.binarybits.net/hide-sharepoint-list-column/ https://blog.binarybits.net/hide-sharepoint-list-column/#respond Thu, 13 Jul 2017 07:18:40 +0000 https://blog.binarybits.net/?p=908 Sometimes we need to hide specific SharePoint columns in a list view webpart. The following code will help with that. Make sure this code is placed in a JS file and referenced using JSLink webpart property. Just replace the HideColumn function’s array parameters [“Title”, “Created By”] with necessary column’s display names. (function () { var overrideCurrentContext […]

The post Hide SharePoint list column appeared first on Binary Bits.

]]>
Sometimes we need to hide specific SharePoint columns in a list view webpart. The following code will help with that.
Make sure this code is placed in a JS file and referenced using JSLink webpart property.
Just replace the HideColumn function’s array parameters [“Title”, “Created By”] with necessary column’s display names.

(function () {
    var overrideCurrentContext = {};
    overrideCurrentContext.Templates = {};
    overrideCurrentContext.OnPostRender = PostRenderer;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
})();

function PostRenderer(ctx) {
    HideColumn(["Title", "Created By"],true);
}

function HideColumn(columns, hideOnlyHeader) {
    columns.forEach(function(columnName) {
        headerParentFirstNode = document.querySelectorAll("[displayname='" + columnName + "']")[0];
        if (headerParentFirstNode != undefined) {
            var header = headerParentFirstNode.parentNode;
            header.style.display = "none";
            if (!hideOnlyHeader) {
                var index = [].slice.call(header.parentNode.children).indexOf(header) + 1;
                for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) {
                    cells[i].style.display = "none";
                }
            }
        }
    });
}

 

The post Hide SharePoint list column appeared first on Binary Bits.

]]>
https://blog.binarybits.net/hide-sharepoint-list-column/feed/ 0