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 IgrGrid
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:
- Ocultação de coluna
- Fixação de coluna
- Exportação do Excel
- Filtragem avançada
The toolbar and the predefined UI components support React events and expose API for developers.
React Toolbar Grid Example
The predefined Actions
and title
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 key="toolbar">
<IgrGridToolbarTitle key="toolbarTitle">
<span key="toolbarTitleText">Grid Toolbar<span>
</IgrGridToolbarTitle>
<IgrGridToolbarActions key="toolbarActions">
<IgrGridToolbarAdvancedFiltering key="advancedFiltering"></IgrGridToolbarAdvancedFiltering>
<IgrGridToolbarPinning key="pinning"></IgrGridToolbarPinning>
<IgrGridToolbarHiding key="hiding"></IgrGridToolbarHiding>
<IgrGridToolbarExporter key="export"></IgrGridToolbarExporter>
</IgrGridToolbarActions>
</IgrGridToolbar>
</IgrGrid>
[!Note] As seen in the code snippet above, the predefined
Actions
UI components are wrapped in theIgrGridToolbarActions
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:
<IgrGrid>
<IgrGridToolbar key="toolbar">
</IgrGridToolbar>
</IgrGrid>
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
The toolbar is great at separating logic/interactions which affects the grid as a whole.
As shown above, it can be configured to provide default components for controlling, column hiding, column pinning, advanced filtering and exporting data from the grid.
These features can be enabled independently from each other by following a pattern similar to the card component of the Ignite UI for React suite.
Listed below are the main features of the toolbar with example code for each of them.
Title
Setting a title for the toolbar in your grid is achieved by using the IgrGridToolbarTitle
.
Users can provide anything from simple text to more involved templates.
<IgrGridToolbar key="toolbar">
<IgrGridToolbarTitle key="toolbarTitle">
<span key="toolbarTitleText">Grid toolbar title<span>
</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 key="toolbar">
<IgrGridToolbarActions key="toolbarActions">
</IgrGridToolbarActions>
</IgrGridToolbar>
Fixação de coluna
The IgrGridToolbarPinning
component provides the default UI for interacting with column pinning in the grid.
The component is setup to work out of the box with the parent grid containing the toolbar as well as several 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 key="toolbar">
<IgrGridToolbarActions key="toolbarActions">
<IgrGridToolbarPinning key="pinning" title="Grid pinned columns" prompt="Filter column collection" columnListHeight="400px"></IgrGridToolbarPinning>
</IgrGridToolbarActions>
</IgrGridToolbar>
Ocultação de coluna
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 key="toolbar">
<IgrGridToolbarActions key="toolbarActions">
<IgrGridToolbarHiding key="hiding" title="Grid column hiding" prompt="Filter column collection" columnListHeight="400px"></IgrGridToolbarHiding>
</IgrGridToolbarActions>
</IgrGridToolbar>
Filtragem avançada
Toolbar Advanced Filtering component provides the default UI for the Advanced Filtering feature. The component exposes a way to change the default text of the button.
<IgrGridToolbar key="toolbar">
<IgrGridToolbarActions key="toolbarActions">
<IgrGridToolbarAdvancedFiltering key="advancedFiltering"></IgrGridToolbarAdvancedFiltering>
</IgrGridToolbarActions>
</IgrGridToolbar>
Data Exporting
As with the rest of the toolbar actions, exporting is provided through a IgrGridToolbarExporter
out of the box.
The toolbar exporter component exposes several input properties for customizing both the UI and the exporting experience.
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
.
Here is a snippet showing some of the options which can be customized through the React template:
<IgrGridToolbar key="toolbar">
<IgrGridToolbarActions key="toolbarActions">
<IgrGridToolbarExporter key="export" 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.
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:
function 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 toolbarExporting={configureExport}>
</IgrGrid>
O exemplo a seguir demonstra como personalizar os arquivos exportados:
Exporting Indicator
When using the default toolbar exporter component, whenever an export operation takes place the toolbar will show a progress indicator while the operation is in progress.
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.
The sample belows uses has significant amount of data, in order to increase the time needed for data export so the progressbar can be seen. Additionally it has another button that simulates a long running operation in the grid:
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:
<IgrGrid className="grid"></IgrGrid>
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.
IgrGrid
Events:ToolbarExporting
Additional Resources
Nossa comunidade é ativa e sempre acolhedora para novas ideias.