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 365 and Office Office Online Server
Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office SharePoint Server Development
{count} votes

1 answer

Sort by: Most helpful
  1. ZhengyuGuo 10,586 Reputation points Moderator
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.