Blazor Selección de celda de cuadrícula

    The Ignite UI for Blazor Cell Selection in Blazor Grid enables rich data select capabilities and offers powerful API in the IgbGrid component. The Blazor Grid supports three selection modes:

    • Selección de celdas múltiples de cuadrícula
    • Selección única de cuadrícula
    • Cuadrícula Ninguna selección

    Profundicemos en cada una de estas opciones.

    Blazor Grid Cell Selection Example

    The sample below demonstrates the three types of IgbGrid's cell selection behavior. Use the buttons below to enable each of the available selection modes. A brief description will be provided on each button interaction through a snackbar message box.

    Selection Types

    Grid Multiple-Cell Selection

    Cómo seleccionar celdas:

    • Arrastrando con el mouse: se realizará la selección de datos rectangulares de las celdas.
    • Al CTRL presionar la tecla + arrastrar el mouse, se realizarán múltiples selecciones de rango. Se conservará cualquier otra selección de celdas existente.
    • Selección instantánea de varias celdas mediante el uso SHIFT de la llave. Seleccione una sola celda y seleccione otra celda individual manteniendo presionada la SHIFT tecla. Se seleccionará el rango de celdas entre las dos celdas. Tenga en cuenta que si se selecciona otra segunda celda mientras se mantiene presionada SHIFT la tecla, el rango de selección de celda se actualizará en función de la posición de la primera celda seleccionada (punto de inicio).
    • Selección de varias celdas del teclado usando las Arrow teclas mientras mantiene presionada SHIFT la tecla. El rango de selección de varias celdas se creará en función de la celda enfocada.
    • Selección de varias celdas del teclado usando las teclas + ​ ​ y CTRL + HOME / END mientras mantiene presionada SHIFT la CTRL tecla. El rango de selección de varias celdas se creará en función de la celda enfocada.
    • Al hacer clic con la tecla izquierda del mouse mientras mantiene presionada CTRL la tecla, se agregarán rangos de celdas individuales a la colección de celdas seleccionadas.
    • La selección continua de múltiples celdas está disponible haciendo clic con el mouse y arrastrando.

    Manifestación

    Selección única de cuadrícula

    When you set the CellSelection to single, this allows you to have only one selected cell in the grid at a time. Also the mode mouse drag will not work and instead of selecting a cell, this will make default text selection.

    When single cell is selected Selected event is emitted, no matter if the selection mode is single or multiple. In multi-cell selection mode when you select a range of cells RangeSelected event is emitted.

    Cuadrícula Ninguna selección

    If you want to disable cell selection you can just set CellSelection to none. In this mode when you click over the cell or try to navigate with keyboard, the cell is not selected, only the activation style is applied and it is going to be lost when you scroll or click over other element on the page. The only way for you to define selection is by using the API methods that are described below.

    Keyboard Navigation Interactions

    While Shift Key is Pressed

    • SHIFT + para agregar la celda anterior a la selección actual.
    • SHIFT + para agregar la celda inferior a la selección actual.
    • SHIFT + para agregar la celda izquierda a la selección actual.
    • SHIFT + para agregar la celda derecha a la selección actual.

    While Ctrl + Shift Keys are Pressed

    • CTRL + SHIFT + para seleccionar todas las celdas por encima de la celda enfocada en la columna.
    • CTRL + SHIFT + para seleccionar todas las celdas debajo de la celda enfocada en la columna.
    • CTRL + SHIFT + para seleccionar todas las celdas hasta el comienzo de la fila.
    • CTRL + SHIFT + para seleccionar todas las celdas hasta el final de la fila.
    • CTRL + SHIFT + HOME para seleccionar todas las celdas de la celda enfocada hasta la primera celda de la cuadrícula
    • CTRL + SHIFT + END para seleccionar todas las celdas de la celda enfocada hasta la última celda de la cuadrícula

    [!Note] Continuous scroll is possible only within Grid's body.

    Api Usage

    A continuación se detallan los métodos que puede utilizar para seleccionar rangos, borrar la selección u obtener datos de celdas seleccionadas.

    Select range

    SelectRange - Select a range of cells with the API. rowStart and rowEnd should use row indexes and columnStart and columnEnd could use column index or column data field value.

    <IgbGrid @ref=grid  CellSelection="GridSelectionMode.Multiple" AutoGenerate=true></<IgbGrid>
    
    @code {
        private IgbGrid grid;
    
        private async void SetSelection()
        {
            IgbGridSelectionRange selectionRange = new IgbGridSelectionRange();
            selectionRange.ColumnStart = 1;
            selectionRange.ColumnEnd = 1;
            selectionRange.RowStart = 2;
            selectionRange.RowEnd = 2;
    
            this.grid.SelectRange(new IgbGridSelectionRange[] {});
        }
    }
    

    Clear cell selection

    ClearCellSelection will clear the current cell selection.

    @code {
        private async void ClearSelection()
        {
            await this.grid.ClearCellSelectionAsync();
        }
    }
    

    Get Selected Data

    GetSelectedData will return array of the selected data in Dictionary format. Examples below:

    <IgbGrid @ref=grid  CellSelection="GridSelectionMode.Multiple" AutoGenerate=true></<IgbGrid>
    
    @code {
        private IgbGrid grid;
    
        private async void GetSelectedData()
        {
            object[] data = await this.grid.GetSelectedDataAsync(true, true);
        }
    }
    

    Features Integration

    La selección de varias celdas se basa en índices (selección de elementos DOM).

    • Sorting - When sorting is performed selection will not be cleared. It will leave currently selected cells the same while sorting ascending or descending.
    • Paging - On paging selected cells will be cleared. Selection wont be persisted across pages.
    • Filtering - When filtering is performed selection will not be cleared. If filtering is cleared it will return - the initially selected cells.
    • Resizing - On column resizing selected cells will not be cleared.
    • Hiding - It will not clear the selected cells. If column is hidden, the cells from the next visible column will be selected.
    • Pinning - Selected cell will not be cleared. Same as hiding
    • GroupBy - On column grouping selected cells will not be cleared.

    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 configure las propiedades CSS relacionadas para esa clase:

    .grid {
        --ig-grid-cell-selected-text-color: #FFFFFF;
        --ig-grid-cell-active-border-color: #f2c43c;
        --ig-grid-cell-selected-background: #0062A3;
    }
    

    Manifestación

    API References

    Additional Resources

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