Dear support,
Is it possible to display a column based on user role in a Blazor Server app?
e.g. "admin" will be able to see the column with name DOB but "Simpleuser" role will not be able to see that column.
Can you please provide a working sample?
thank you
<SfGrid DataSource="@Orders">
@if (Role == "admin")
{
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.DOB) HeaderText="DOB" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
}
else
{
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
}
</SfGrid> |
Hello,
can you please provide a simple working sample with 2 roles that demonstrate the above?
thanks
<button @onclick="ChangeRole">ChangeRole</button>
<SfGrid DataSource="@Orders">
@if (Role == "admin")
{
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.DOB) HeaderText="DOB" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
}
else
{
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
}
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public string Role { get; set; } = "admin";
public void ChangeRole()
{
if (Role == "admin")
{
Role = "user";
}
else
{
Role = "admin";
}
}
} |