Clasificación de cuadrícula Blazor

    La función Ignite UI for Blazor Data Sorting en Blazor Grid está habilitada a nivel de columna, lo que significa que IgbGrid puede tener una combinación de columnas ordenables y no ordenables. La realización de acciones de clasificación Blazor le permite cambiar el orden de visualización de los registros según criterios específicos.

    Blazor Grid Sorting Overview Example

    Esto se hace a través de la entrada Sortable. Con la clasificación IgbGrid, también puede configurar la propiedad SortingIgnoreCase para realizar una clasificación que distinga entre mayúsculas y minúsculas:

    <IgbColumn Field="Title" Sortable="true"></IgbColumn>
    

    Sorting Indicators

    Tener una cierta cantidad de columnas ordenadas puede resultar realmente confuso si no hay ninguna indicación del orden de clasificación.

    IgbGrid proporciona una solución a este problema indicando el índice de cada columna ordenada.

    Sorting through the API

    Puede ordenar cualquier columna o una combinación de columnas a través de la API IgbGrid utilizando el método IgbGrid Sort:

    @code {
        this.grid.SortAsync(new IgbSortingExpression[]
            {
                new IgbSortingExpression
                {
                    FieldName = "CompanyName",
                    Dir = SortingDirection.Asc
                },
                new IgbSortingExpression
                {
                    FieldName = "Country",
                    Dir = SortingDirection.Asc
                }
            });
    }
    

    [!Note] Sorting is performed using our DefaultSortingStrategy algorithm. Any IgbColumn or ISortingExpression can use a custom implementation of the ISortingStrategy as a substitute algorithm. This is useful when custom sorting needs to be defined for complex template columns, or image columns, for example.

    Al igual que con el comportamiento de filtrado, puede borrar el estado de clasificación utilizando el método ClearSort:

    @code {
        @*Removes the sorting state from the Title column*@
        this.grid.ClearSortAsync("Title");
    
        @*Removes the sorting state from every column in the Grid*@
        this.grid.ClearSortAsync("");
    }
    

    [!Note] The SortStrategy of the IgbGrid is of different type compared to the SortStrategy of the IgbColumn, since they work in different scopes and expose different parameters.

    [!Note] The sorting operation DOES NOT change the underlying data source of the IgbGrid.

    Initial Sorting State

    Es posible establecer el estado de clasificación inicial de IgbGrid pasando una matriz de expresiones de clasificación a la propiedad SortingExpressions de IgbGrid.

    @code {
        protected override void OnAfterRender(bool first)
        {
            if (first)
            {
                this.grid.SortingExpressions = new IgbSortingExpression[]{
                    new IgbSortingExpression()
                    {
                        FieldName = "Title",
                        Dir = SortingDirection.Asc
                    }};
            }
        }
    }
    

    [!Note] If values of type string are used by a column of DataType Date, the IgbGrid won't parse them to Date objects and using IgbGrid Sorting won't work as expected. If you want to use string objects, additional logic should be implemented on an application level, in order to parse the values to Date objects.

    Sorting Indicators Templates

    El icono del indicador de clasificación en el encabezado de la columna se puede personalizar mediante una plantilla. Las siguientes propiedades están disponibles para crear plantillas del indicador de clasificación para cualquier estado de clasificación (ascendente, descendente, ninguno):

    • SortHeaderIconTemplate: vuelve a crear una plantilla para el icono de clasificación cuando no se aplica ninguna clasificación.
    <IgbGrid SortHeaderIconTemplate="SortDefaultTemplate"></IgbGrid>
    
    @code {
        public RenderFragment<IgbGridHeaderTemplateContext> SortDefaultTemplate = (ctx) =>
        {
            return @<IgbIcon Size="SizableComponentSize.Small" IconName="unfold_more" Collection="material"></IgbIcon>;
        };
    }
    
    <IgbGrid SortAscendingHeaderIconTemplate="SortAscendingTemplate"></IgbGrid>
    
    @code {
        public RenderFragment<IgbGridHeaderTemplateContext> SortAscendingTemplate = (ctx) =>
        {
            return @<IgbIcon Size="SizableComponentSize.Small" IconName="expand_less" Collection="material"></IgbIcon>;
        };
    }
    
    <IgbGrid SortDescendingHeaderIconTemplate="SortDescendingTemplate"></IgbGrid>
    
    @code {
        public RenderFragment<IgbGridHeaderTemplateContext> SortDescendingTemplate = (ctx) =>
        {
            return @<IgbIcon Size="SizableComponentSize.Small" IconName="expand_more" Collection="material"></IgbIcon>;
        };
    }
    

    Styling

    Además de los temas predefinidos, la cuadrícula se puede personalizar aún más configurando algunas de las propiedades CSS disponibles. En caso de que desee cambiar algunos de los colores, primero debe establecer una clase para la cuadrícula:

    <IgbGrid class="grid">
    </IgbGrid>
    

    Luego establezca las propiedades CSS relacionadas con esta clase:

    .grid {
        --ig-grid-sorted-header-icon-color: #ffb06a;
        --ig-grid-sortable-header-icon-hover-color: black;
    }
    

    Demo

    API References

    Additional Resources

    Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.