How to hide list columns in SharePoint webpart based on user role?

Power Platform Resource 1 Reputation point
2021-01-15T23:34:05.773+00:00

Hi,

I am successfully hiding list view columns in web part based on user role using following script line.

$("div.ms-vh-div[DisplayName='Column X']").attr("style", "display: none");

but it's hiding only div tag but keeping the extra space as shown in pic. How to hide this extra space?Any help would be greatly appreciated.

57331-image.png

Thank you in advance.

Microsoft Office Online Server
Microsoft Office Online Server
Microsoft on-premises server product that runs Office Online. Previously known as Office Web Apps Server.
586 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
872 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,575 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jerryzy 10,566 Reputation points
    2021-01-18T05:34:00.423+00:00

    Hi @Power Platform Resource ,

    Please use the JsLink code in attachment file to hide specific column in list view web part, it will hide column and won't leave the extra space:

    57472-jslink.txt

    Remember to change the field name in the code (red line) below with yours so that it will work as expected:

    57426-snipaste-2021-01-18-13-31-30.png

    Thanks
    Best Regards


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.