Wrong columns order when using AuthorizeView

Hi,

When using AuthorizeView to conditionnally display some columns, the columns inside AuthorizeView will be displayed at the end of the DataGrid no matter where they are declared in the code.


For example the "Second" column will be display as the last column :

<GridColumn Field="@nameof(dto.First)" HeaderText="First" />
<AuthorizeView Policy="IsAdmin">
    <Authorized>
         <GridColumn Field="@nameof(dto.Second)" HeaderText="Second" />
    </Authorized>
</AuthorizeView>
<GridColumn Field="@nameof(dto.Thrird)" HeaderText="Third" />


Is there a way to keep the right order and keep using AuthorizeView ?


Regards.


1 Reply

NP Naveen Palanivel Syncfusion Team May 22, 2025 11:29 AM UTC

Hi Julien Barach,

When rendering a GridColumn by enclosing it inside an AuthorizeView, you may encounter an issue where the GridColumn is rendered as the last column in the grid, regardless of the order in which it is defined inside GridColumns. To overcome this issue, it is recommended to render the specific GridColumn inside the AuthorizeView as a separate custom component that inherits from GridColumn. Please refer to and use the code example below.

<SfGrid DataSource="@Data" @ref="Grid" AllowSelection=true AllowPaging="true">

    <GridColumns>

        <GridColumn Field="@nameof(dto.First)" HeaderText="First" Width="100" TextAlign="TextAlign.Center" />

 

        <AuthorizeView Policy="IsAdmin">

            <Authorized>

                <GridColumnComponent Field="@nameof(dto.Second)" HeaderText="Second" Width="100" TextAlign="TextAlign.Center" />

            </Authorized>

        </AuthorizeView>

 

        <GridColumn Field="@nameof(dto.Thrird)" HeaderText="Third" Width="100" TextAlign="TextAlign.Center" />

    </GridColumns>

</SfGrid>

[GridColumnComponent.razor]

 

@using Syncfusion.Blazor.Grids

 

@using static BlazorApp.Components.Pages.Home

 

<h3>GridColumnComponent</h3>

 

 

@inherits GridColumn

 

<CascadingValue Value="@this">

 

    @ChildContent

 

</CascadingValue>


Regards,
Naveen


Loader.
Up arrow icon