Web Components Tree Grid Toolbar

    The Ignite UI for Web Components Toolbar in is a container for UI operations in the Web Components Tree Grid. The Web Components toolbar is located at the top of the Web Components component, i.e., the IgcTreeGridComponent 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 Web Components Tree Grid includes:

    • Ocultação de coluna
    • Fixação de coluna
    • Exportação do Excel
    • Filtragem avançada

    A barra de ferramentas e os componentes de interface do usuário predefinidos dão suporte a eventos Web Components e expõem a API para desenvolvedores.

    Web Components Toolbar Grid Example

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

    <igc-tree-grid id="treeGrid" primary-key="ID" foreign-key="ParentID" auto-generate="true">
        <igc-grid-toolbar>
            <igc-grid-toolbar-title>Tree Grid Toolbar</igc-grid-toolbar-title>
            <igc-grid-toolbar-actions>
                <igc-grid-toolbar-advanced-filtering><igc-grid-toolbar-advanced-filtering>
                <igc-grid-toolbar-hiding></igc-grid-toolbar-hiding>
                <igc-grid-toolbar-pinning></igc-grid-toolbar-pinning>
                <igc-grid-toolbar-exporter></igc-grid-toolbar-exporter>
            </igc-grid-toolbar-actions>
        </igc-grid-toolbar>
    </igc-tree-grid>
    

    [!Note] As seen in the code snippet above, the predefined Actions UI components are wrapped in the IgcGridToolbarActionsComponent 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.

    Obviamente, cada uma dessas interfaces do usuário pode ser adicionada independentemente uma da outra ou pode não ser adicionada. Dessa forma, o contêiner da barra de ferramentas será renderizado vazio:

    <igc-tree-grid primary-key="ID" foreign-key="ParentID" auto-generate="true">
        <igc-grid-toolbar>
        </igc-grid-toolbar>
    </igc-tree-grid>
    

    Para obter uma visão abrangente de cada um dos componentes padrão da interface do usuário, continue lendo a seção Recursos abaixo.

    Características

    A barra de ferramentas é ótima para separar lógica / interações que afetam a grade como um todo.

    Conforme mostrado acima, ele pode ser configurado para fornecer componentes padrão para controle, ocultação de coluna, fixação de coluna, filtragem avançada e exportação de dados da grade.

    Esses recursos podem ser ativados independentemente uns dos outros, seguindo um padrão semelhante ao componente de cartão do pacote Ignite UI for Web Components.

    Abaixo estão listados os principais recursos da barra de ferramentas com código de exemplo para cada um deles.

    Title

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

    Os usuários podem fornecer qualquer coisa, desde texto simples até modelos mais complexos.

    <igc-grid-toolbar>
        <igc-grid-toolbar-title>Grid toolbar title</igc-grid-toolbar-title>
    </igc-grid-toolbar>
    

    Actions

    The IgcGridToolbarActionsComponent 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.

    <igc-grid-toolbar>
        <igc-grid-toolbar-actions>
        <!-- ... -->
        </igc-grid-toolbar-actions>
    </igc-grid-toolbar>
    

    Fixação de coluna

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

    O componente é configurado para funcionar imediatamente com a grade pai contendo a barra de ferramentas, bem como várias propriedades de entrada para personalizar a interface do usuário, como o título do componente, o espaço reservado para a entrada do componente e a altura da própria lista suspensa.

    <igc-grid-toolbar>
        <igc-grid-toolbar-actions>
            <igc-grid-toolbar-pinning
                title="Grid pinned columns"
                prompt="Filter column collection"
                column-list-height="400px">
            </igc-grid-toolbar-pinning>
        </igc-grid-toolbar-actions>
    </igc-grid-toolbar>
    

    Ocultação de coluna

    The IgcGridToolbarHidingComponent 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.

    <igc-grid-toolbar>
        <igc-grid-toolbar-actions>
            <igc-grid-toolbar-hiding
                title="Grid column hiding"
                prompt="Filter column collection"
                column-list-height="400px">
            </igc-grid-toolbar-hiding>
        </igc-grid-toolbar-actions>
    </igc-grid-toolbar>
    

    Filtragem avançada

    O componente Filtragem Avançada da Barra de Ferramentas fornece a interface do usuário padrão para o recurso Filtragem Avançada. O componente expõe uma maneira de alterar o texto padrão do botão.

    <igc-grid-toolbar>
        <igc-grid-toolbar-actions>
            <igc-grid-toolbar-advanced-filtering>Custom text for the toggle button</igc-grid-toolbar-advanced-filtering>
        </igc-grid-toolbar-actions>
    </igc-grid-toolbar>
    

    Data Exporting

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

    O componente exportador da barra de ferramentas expõe várias propriedades de entrada para personalizar a interface do usuário e a experiência de exportação.

    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.

    Aqui está um trecho mostrando algumas das opções que podem ser personalizadas por meio do modelo Web Components:

    <igc-grid-toolbar>
        <igc-grid-toolbar-actions>
            <igc-grid-toolbar-exporter export-csv="true" export-excel="true" filename="exported_data">
            </igc-grid-toolbar-exporter>
        </igc-grid-toolbar-actions>
    </igc-grid-toolbar>
    

    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.

    O snippet de código a seguir demonstra a assinatura do evento de exportação da barra de ferramentas e a configuração das opções do exportador:

    <igc-tree-grid id="treeGrid"></igc-tree-grid>
    
    constructor() {
        var treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
        treeGrid.addEventListener("toolbarExporting", this.configureExport);
    }
    
    public configureExport(evt: CustomEvent<IgcGridToolbarExportEventArgs>) {
        const args = evt.detail;
        const options: IgcExporterOptionsBase = args.options;
        if (options) {
            options.fileName = `Report_${new Date().toDateString()}`;
            (args.exporter as any).columnExporting.subscribe((columnArgs: any) => {
                columnArgs.cancel = columnArgs.header === 'Name';
            });
        }
    }
    

    O exemplo a seguir demonstra como personalizar os arquivos exportados:

    Exporting Indicator

    Ao usar o componente exportador da barra de ferramentas padrão, sempre que uma operação de exportação ocorrer, a barra de ferramentas mostrará um indicador de progresso enquanto a operação estiver em andamento.

    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.

    O exemplo abaixo usa uma quantidade significativa de dados, a fim de aumentar o tempo necessário para a exportação de dados para que a barra de progresso possa ser vista. Além disso, possui outro botão que simula uma operação de longa duração na grade:

    Custom Content

    Se a parte de ações do componente da barra de ferramentas não for suficiente para um caso de uso específico, a própria barra de ferramentas terá uma projeção de conteúdo geral em que os usuários podem fornecer interface do usuário adicional. Se o usuário precisar da respectiva instância de grade para chamadas ou associações de API, ele poderá criar uma variável de referência de modelo.

    Aqui está um trecho de exemplo:

    <igc-tree-grid id="grid">
        <igc-grid-toolbar>
            <igc-grid-toolbar-title>title</igx-grid-toolbar-title>
            <!--
                Everything between the toolbar tags except the default toolbar components/directives
                will be projected as custom content.
             -->
            <igc-grid-toolbar-actions>
            </igc-grid-toolbar-actions>
        </igc-grid-toolbar>
    </igc-tree-grid>
    

    O exemplo a seguir demonstra como adicionar um botão adicional à barra de ferramentas para limpar o conjunto de classificação clicando nos cabeçalhos das colunas:

    Styling

    Além dos temas predefinidos, a grade pode ser ainda mais personalizada ao definir algumas das propriedades CSS disponíveis. Caso você queira alterar algumas das cores, precisa definir uma classe para a grade primeiro:

    <igc-tree-grid class="grid"></igc-tree-grid>
    

    Em seguida, defina as propriedades CSS relacionadas para essa classe:

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

    Demo

    API References

    O serviço Grid Toolbar tem mais algumas APIs para explorar, listadas abaixo.

    IgcTreeGridComponent Events:

    • ToolbarExporting

    Additional Resources

    Nossa comunidade é ativa e sempre acolhedora para novas ideias.