Web Components Tamanho da grade da árvore
O recurso Tamanho Ignite UI for Web Components em Web Components Grade de Árvore permite que os usuários controlem o espaçamento e o layout dos dados dentro do IgcTreeGridComponent
. Ao alterar--ig-size
, você pode melhorar significativamente a experiência do usuário ao interagir com grandes quantidades de conteúdo. Eles podem escolher entre três opções de tamanho:
--ig-size-large
--ig-size-medium
--ig-size-small
Web Components Tree Grid Size Example
Usage
Como você pode ver na demonstração acima, o fornece IgcTreeGridComponent
três opções de tamanho: pequeno, médio e grande. O trecho de código abaixo mostra como definir--ig-size
inline ou parte de uma classe CSS:
.gridSize {
--ig-size: var(--ig-size-medium);
}
<igc-tree-grid id="grid" class="gridSize">
</igc-tree-grid>
E agora vamos ver em detalhes como cada opção reflete no IgcTreeGridComponent
componente. Quando você alterna entre diferentes opções de tamanho, a altura de cada IgcTreeGridComponent
elemento e os preenchimentos correspondentes serão alterados. Além disso, se você quiser aplicar uma coluna width
personalizada, considere o fato de que ela deve ser maior que a soma do preenchimento esquerdo e direito.
- grande- este é o tamanho padrão
IgcTreeGridComponent
com o menor intenso e altura de linha igual a50px
. Os preenchimentos esquerdo e direito são24px
; A colunawidth
mínima é80px
; - Médio- Este é o tamanho médio intenso com
40px
altura da linha. Os preenchimentos esquerdo e direito são16px
; A colunawidth
mínima é64px
; - Pequeno- Este é o tamanho com maior intensidade e
32px
altura de linha. Os preenchimentos esquerdo e direito são12px
; A colunawidth
mínima é56px
;
[!Note] Please keep in mind that currently you can not override any of the sizes.
Vamos agora continuar com nosso exemplo e ver em ação como o--ig-size
é aplicado. Vamos primeiro adicionar um botão que nos ajudará a alternar entre cada tamanho:
<div class="size-chooser">
<igc-property-editor-panel
description-type="WebTreeGrid"
is-horizontal="true"
is-wrapping-enabled="true"
name="PropertyEditor"
id="propertyEditor">
<igc-property-editor-property-description
name="SizeEditor"
id="SizeEditor"
label="Grid Size:"
value-type="EnumValue"
drop-down-names="Small, Medium, Large"
drop-down-values="Small, Medium, Large">
</igc-property-editor-property-description>
</igc-property-editor-panel>
</div>
Agora podemos adicionar a marcação.
<igc-tree-grid id="grid" primary-key="ID" foreign-key="ParentID" width="100%"
height="550px" allow-filtering="true">
<igc-column field="Name" data-type="String" sortable="true" has-summary="true" width="200px"></igc-column>
<igc-column-group pinned="false" header="General Information">
<igc-column field="HireDate" data-type="Date" sortable="true" has-summary="true">
</igc-column>
<igc-column-group header="Person Details">
<igc-column field="ID" data-type="Number" filterable="false"></igc-column>
<igc-column field="Title" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="Age" data-type="Number" sortable="true" has-summary="true" filterable="false"></igc-column>
</igc-column-group>
</igc-column-group>
<igc-column-group header="Address Information">
<igc-column-group header="Location">
<igc-column field="Country" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="City" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="Address" data-type="String" sortable="true" has-summary="true"></igc-column>
</igc-column-group>
<igc-column-group header="Contact Information">
<igc-column field="Phone" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="Fax" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="PostalCode" data-type="String" sortable="true" has-summary="true"></igc-column>
</igc-column-group>
</igc-column-group>
<igc-column-group header="Address Information">
<igc-column-group header="Location">
<igc-column field="Country" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="City" data-type="String" sortable="true" has-summary="true"></igc-column>
<igc-column field="Address" data-type="String" sortable="true" has-summary="true"></igc-column>
</igc-column-group>
<igc-column-group header="Contact Information">
<igc-column field="Phone" data-type="String" sortable="true" resizable="true"></igc-column>
<igc-column field="Fax" data-type="String" sortable="true" resizable="true"></igc-column>
<igc-column field="PostalCode" data-type="String" sortable="true" resizable="true"></igc-column>
</igc-column-group>
</igc-column-group>
</igc-tree-grid>
Finalmente, vamos fornecer a lógica necessária para realmente aplicar o tamanho:
constructor() {
var propertyEditor = this.propertyEditor = document.getElementById('PropertyEditor') as IgcPropertyEditorPanelComponent;
var sizeEditor = this.sizeEditor = document.getElementById('SizeEditor') as IgcPropertyEditorPropertyDescriptionComponent;
var grid = this.grid = document.getElementById('grid') as IgcTreeGrid;
propertyEditor.componentRenderer = this.renderer;
propertyEditor.target = this.grid;
this.webGridSetGridSize = this.webGridSetGridSize.bind(this);
sizeEditor.changed = this.webGridSetGridSize;
grid.data = this.data;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
public webGridSetGridSize(sender: any, args: IgcPropertyEditorPropertyDescriptionChangedEventArgs): void {
var newVal = (args.newValue as string).toLowerCase();
var grid = document.getElementById("grid");
grid.style.setProperty('--ig-size', `var(--ig-size-${newVal})`);
}
Outra opção que IgcTreeGridComponent
fornece para você, para poder alterar a altura das linhas no IgcTreeGridComponent
, é a propriedade RowHeight
. Então, vamos ver em ação como essa propriedade afeta o IgcTreeGridComponent
layout junto com o--ig-size
.
Lembre-se do seguinte:
--ig-size
A variável CSS não terá impacto na altura da linha se forRowHeight
especificada.--ig-size
afetará todos os demais elementos na Grade de Árvore, conforme descrito acima.
Agora podemos estender nosso exemplo e adicionar RowHeight
propriedade ao IgcTreeGridComponent
:
<igc-tree-grid id="grid" class="gridSize" row-height="80px" width="100%" height="550px" allow-filtering="true">
</igc-tree-grid>
API References
Nossa comunidade é ativa e sempre acolhedora para novas ideias.