Setting Grid Properties via c# Code

Hello,

How to set DATAGRID properties via c# in @code {} section of razor page such as:

- AllowSorting,AllowFiltering, AllowExcelExport, ....

- GridPageSettings,

- GridEditSettings,

- GridFilterSettings,

- GridSelectionSettings.

Greetings.




3 Replies

PS Prathap Senthil Syncfusion Team November 25, 2024 12:12 PM UTC


Hi LAID,

Greetings from Syncfusion,

Based on your requirement set Grid properties within the @code section of a Razor page, you can bind these properties to variables and update them in your C# code. Kindly refer to the below code snippet and sample for your reference,

@using Syncfusion.Blazor.Grids

 

<SfGrid TValue="Order" DataSource="Orders" AllowSorting="@AllowSorting" AllowFiltering="@AllowFiltering" AllowExcelExport="@AllowExcelExport" PageSettings="@pageSettings" EditSettings="@editSettings" FilterSettings="@filterSettings" SelectionSettings="@selectionSettings">

  

</SfGrid>

 

@code {

    private bool AllowSorting { get; set; } = true;

    private bool AllowFiltering { get; set; } = true;

    private bool AllowExcelExport { get; set; } = false;

 

 

    private GridPageSettings pageSettings { get; set; } = new GridPageSettings { PageSize = 10 };

    private GridEditSettings editSettings { get; set; } = new GridEditSettings { AllowAdding = true, AllowEditing = true, AllowDeleting = true };

    private GridFilterSettings filterSettings { get; set; } = new GridFilterSettings { Type = Syncfusion.Blazor.Grids.FilterType.Menu };

    private GridSelectionSettings selectionSettings { get; set; } = new GridSelectionSettings { Type = Syncfusion.Blazor.Grids.SelectionType.Single };

 

}


Sample:https://blazorplayground.syncfusion.com/embed/BNLzMMhoAnFFMGYH?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

Regards,
Prathap Senthil



LA LAID November 25, 2024 04:54 PM UTC

Thank you very much

it helped me to minimize my code.



PS Prathap Senthil Syncfusion Team November 27, 2024 03:44 AM UTC

Thanks for the update, We are happy to hear that the provided information was helpful. We are closing the thread now.


Loader.
Up arrow icon