Reputation: 243
I am using Kendo ui grid in asp.net MVC. Is it possible to hide/show grid column based on user role? Thanks
Upvotes: 6
Views: 4438
Reputation:
You can specify if a column is visible using hidden, so one option may be to set a variable based on the users role. For example, in the controller
ViewBag.CanDisplay = true; // or omit if the user does not have permission
and in the view
var canDisplay = '@ViewBag.CanDisplay' | false;
$("#grid").kendoGrid({
columns: [
{ field: "firstProperty" },
{ field: "anotherProperty", hidden: !canDisplay }
],
Upvotes: 4
Reputation: 3407
The simplest way is:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id);
columns.Bound(p => p.Name);
if(User.IsInRole("Admin")) {
columns.Bound(p => p.AdminOnlyInfo);
}
})
...
)
Upvotes: 10