React Grid Toolbar

    The Ignite UI for React Toolbar in is a container for UI operations in the React Grid. The React toolbar is located at the top of the React component, i.e., the grid and it matches its horizontal size. The toolbar container can host any custom content or set of predefined UI controls. The default set for the React Grid includes:

    • Ocultación de columna
    • Fijación de columnas
    • Exportación de Excel
    • Filtrado avanzado

    La barra de herramientas y los componentes de UI predefinidos admiten eventos React y exponen API para desarrolladores.

    React Toolbar Grid Example

    The predefined IgrGridToolbarActions and IgrGridToolbarTitle UI components are added inside the IgrGridToolbar and this is all needed to have a toolbar providing default interactions with the corresponding Grid features:

    <IgrGrid>
        <IgrGridToolbar>
            <IgrGridToolbarTitle>
               Grid Toolbar
            </IgrGridToolbarTitle>
            <IgrGridToolbarActions>
                <IgrGridToolbarAdvancedFiltering></IgrGridToolbarAdvancedFiltering>
                <IgrGridToolbarPinning></IgrGridToolbarPinning>
                <IgrGridToolbarHiding></IgrGridToolbarHiding>
                <IgrGridToolbarExporter></IgrGridToolbarExporter>
            </IgrGridToolbarActions>
        </IgrGridToolbar>
    </IgrGrid>
    

    [!Note] As seen in the code snippet above, the predefined Actions UI components are wrapped in the IgrGridToolbarActions container. This way, the toolbar title is aligned to the left of the toolbar and the actions are aligned to the right of the toolbar.

    Por supuesto, cada una de estas UI se puede agregar de forma independiente entre sí o puede que no se agreguen en absoluto. De esta manera, el contenedor de la barra de herramientas quedará vacío:

    <IgrGrid>
        <IgrGridToolbar>
        </IgrGridToolbar>
    </IgrGrid>
    

    Para obtener una visión completa de cada uno de los componentes predeterminados de la interfaz de usuario, continúe leyendo la sección Funciones a continuación.

    Características

    La barra de herramientas es excelente para separar la lógica/interacciones, lo que afecta a la cuadrícula en su conjunto.

    Como se muestra arriba, se puede configurar para proporcionar componentes predeterminados para controlar, ocultar columnas, fijar columnas, filtrar avanzado y exportar datos desde la cuadrícula.

    Estas funciones se pueden habilitar de forma independiente una de otra siguiendo un patrón similar al componente de tarjeta de la suite Ignite UI for React.

    A continuación se enumeran las características principales de la barra de herramientas con código de ejemplo para cada una de ellas.

    Title

    Setting a title for the toolbar in your grid is achieved by using the IgrGridToolbarTitle.

    Los usuarios pueden proporcionar cualquier cosa, desde texto simple hasta plantillas más complejas.

    <IgrGridToolbar>
        <IgrGridToolbarTitle>
            Grid toolbar title
        </IgrGridToolbarTitle>
    </IgrGridToolbar>
    

    Actions

    The IgrGridToolbarActions is where users can place actions/interactions in relation to the parent grid. As with the title portion of the toolbar, users can provide anything inside that template part, including the default toolbar interaction components.

    <IgrGridToolbar>
        <IgrGridToolbarActions>
    
        </IgrGridToolbarActions>
    </IgrGridToolbar>
    

    Fijación de columnas

    The IgrGridToolbarPinning component provides the default UI for interacting with column pinning in the grid.

    El componente está configurado para funcionar desde el primer momento con la cuadrícula principal que contiene la barra de herramientas, así como varias propiedades de entrada para personalizar la interfaz de usuario, como el título del componente, el marcador de posición para la entrada del componente y la altura del menú desplegable.

    <IgrGridToolbar>
        <IgrGridToolbarActions>
            <IgrGridToolbarPinning title="Grid pinned columns" prompt="Filter column collection" columnListHeight="400px"></IgrGridToolbarPinning>
        </IgrGridToolbarActions>
    </IgrGridToolbar>
    

    Ocultación de columna

    The IgrGridToolbarHiding provides the default UI for interacting with column hiding. Exposes the same input properties for customizing the UI, such as the component title, the placeholder for the component input and the height of the dropdown itself.

    <IgrGridToolbar>
        <IgrGridToolbarActions>
            <IgrGridToolbarHiding title="Grid column hiding" prompt="Filter column collection" columnListHeight="400px"></IgrGridToolbarHiding>
        </IgrGridToolbarActions>
    </IgrGridToolbar>
    

    Filtrado avanzado

    El componente Filtrado avanzado de la barra de herramientas proporciona la interfaz de usuario predeterminada para la función Filtrado avanzado. El componente expone una forma de cambiar el texto predeterminado del botón.

    <IgrGridToolbar>
        <IgrGridToolbarActions>
            <IgrGridToolbarAdvancedFiltering></IgrGridToolbarAdvancedFiltering>
        </IgrGridToolbarActions>
    </IgrGridToolbar>
    

    Data Exporting

    As with the rest of the toolbar actions, exporting is provided through a IgrGridToolbarExporter out of the box.

    El componente exportador de la barra de herramientas expone varias propiedades de entrada para personalizar tanto la interfaz de usuario como la experiencia de exportación.

    These range from changing the display text, to enabling/disabling options in the dropdown to customizing the name of the generated file. For full reference, consult the API documentation for the ToolbarExporter.

    A continuación se muestra un fragmento que muestra algunas de las opciones que se pueden personalizar a través de la plantilla React:

    <IgrGridToolbar>
        <IgrGridToolbarActions>
            <IgrGridToolbarExporter exportCSV={true} exportExcel={true} filename="exported_data"></IgrGridToolbarExporter>
        </IgrGridToolbarActions>
    </IgrGridToolbar>
    

    In addition to changing the exported filename, the user can further configure the exporter options by waiting for the ToolbarExporting event and customizing the options entry in the event properties.

    [!Note] By default when exporting to CSV the exporter exports using a comma separator and uses a '.csv' extension for the output file. You can customize these exporting parameters by subscribing to events of the exporter or changing the values of the exporter options fields. You can also cancel the export process by setting the cancel field of the event args to true.

    El siguiente fragmento de código demuestra la suscripción al evento de exportación de la barra de herramientas y la configuración de las opciones del exportador:

    const configureExport = (evt: IgrGridToolbarExportEventArgs) => {
        const args = evt.detail;
        const options: IgrExporterOptionsBase = args.options;
    
        options.fileName = `Report_${new Date().toDateString()}`;
        (args.exporter as any).columnExporting.subscribe((columnArgs: any) => {
                columnArgs.cancel = columnArgs.header === 'Athlete' || columnArgs.header === 'Country';
        });
    }
    
    <IgrGrid onToolbarExporting={configureExport}>
    </IgrGrid>
    

    El siguiente ejemplo demuestra cómo personalizar los archivos exportados:

    Exporting Indicator

    Cuando se utiliza el componente exportador de la barra de herramientas predeterminado, cada vez que se realiza una operación de exportación, la barra de herramientas mostrará un indicador de progreso mientras la operación está en curso.

    Moreover, users can set the toolbar showProgress property and use for their own long running operations or just as another way to signify an action taking place in the grid.

    El ejemplo que se utiliza a continuación tiene una cantidad significativa de datos, a fin de aumentar el tiempo necesario para exportar los datos para que se pueda ver la barra de progreso. Además cuenta con otro botón que simula una operación de larga duración en la red:

    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:

    <IgrGrid className="grid"></IgrGrid>
    

    Luego configure las propiedades CSS relacionadas para esa clase:

    .grid {
        --ig-grid-toolbar-background-color: #2a2b2f;
        --ig-grid-toolbar-title-text-color: #ffcd0f;
        --ig-grid-toolbar-dropdown-background: #2a2b2f;
    }
    

    Demo

    API References

    El servicio Grid Toolbar tiene algunas API más para explorar, que se enumeran a continuación.

    grid Events:

    • ToolbarExporting

    Additional Resources

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