I want to hide some columns of the grid according to a specific width and height of the screen like below.
how to do that?
Hi
Kavindu Gamage,
Greetings from Syncfusion,
Based on your query and requirements, we have prepared a sample using the Media
Query component. Here, we have used '@bind-ActiveBreakPoint,' which activates
when the screen size is small, allowing you to easily hide the columns. For
your reference, we have attached a code snippet and a sample.
|
@using Syncfusion.Blazor @using Syncfusion.Blazor.Grids
<div style="position:relative; min-height: 500px;"> <SfMediaQuery @bind-ActiveBreakPoint="activeBreakpoint" /> @if (activeBreakpoint == "Small") { IsVisible = false; } else { IsVisible = true;
} <SfGrid DataSource="@Orders" AllowSorting="true" AllowFiltering="true"
Height="100%" Width="100%" AllowPaging="true"> <GridFilterSettings Type="@Syncfusion.Blazor.Grids.FilterType.Excel" /> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" Width="80" /> <GridColumn Field=@nameof(Order.CustomerID) Visible="@IsVisible" HeaderText="Customer Name" Width="120" /> <GridColumn Field=@nameof(Order.OrderDate) Visible="@IsVisible" HeaderText=" Order Date" Format="d" Type="Syncfusion.Blazor.Grids.ColumnType.Date" Width="130" /> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="120" /> </GridColumns> </SfGrid> </div>
@code { public List<Order>? Orders { get; set; } private string? activeBreakpoint { get; set; }
public bool IsVisible { get; set; }
SfGrid<Order> Grid { get; set; } }
|
Sample: https://blazorplayground.syncfusion.com/embed/rXrfXGAsqyiuZIYm?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
Reference:
https://blazor.syncfusion.com/documentation/media-query/break-points
https://blazor.syncfusion.com/documentation/datagrid/adaptive-layout#render-adaptive-dialog
Regards,
Prathap Senthil
nice! bro
Thanks for the update,
We are happy to hear that the provided solution was helpful. We are closing the thread now.