How to hide Grid Columns according to specific widths?

I want to hide some columns of the grid according to a specific width and height of the screen like below.

Image_4002_1722318309664

Image_3681_1722318579564

how to do that?



4 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team July 31, 2024 10:41 AM UTC

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

https://blazor.syncfusion.com/documentation/datagrid/adaptive-layout#rendering-an-adaptive-layout-for-smaller-screens-alone



Regards,
Prathap Senthil


Marked as answer

KG Kavindu Gamage replied to Prathap Senthil August 1, 2024 08:19 AM UTC

Thank You Prathap. 



IE ieidhe August 1, 2024 08:32 AM UTC

nice! bro



PS Prathap Senthil Syncfusion Team August 1, 2024 12:31 PM UTC

Thanks for the update,


We are happy to hear that the provided solution was helpful. We are closing the thread now.


Loader.
Up arrow icon