In SharePoint 2013 site, there is a custom list which has a column that should be visible to only one particular SP group.
That column will not be in forms (new/edit/disp) so I don't need hiding it from forms, just in view.
I thought of creating two views and then putting each of them in web part and adding target audiences I could do it, but I am asking if there is some better/nicer way to do this?
2 Answers
For performance-related reasons, the SharePoint doesn't provide column-level security
as OOTB.
The available workarounds
Use the below code to hide a specific column based on a specific group using SPSerevice and JQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function(xData, Status) {
//If the current User does belong to the group "SharePoint Group Name: HamzaQassas"
if($(xData.responseXML).find("Group[Name='HamzaQassas']").length == 1)
{
// Hide the Column with its order ID in List View (Title=2 ...etc)
$(document).ready(function(){$('td:nth-child(2),th:nth-child(2)').hide()});
}
}
});
});
</script>
Output
- Use your mentioned method with multiple views in web part pages and manage
Target Audiences
- Use a 3rd party tool like
Infowise
.
Format the fields using JSLink
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
"Cost_x0020_Status": { "View": FieldTemplate },
};
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function FieldTemplate(ctx) {
}