React Tamanho da grade da árvore

    O recurso Tamanho Ignite UI for React em React Grade de Árvore permite que os usuários controlem o espaçamento e o layout dos dados dentro do IgrTreeGrid. 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

    React Tree Grid Size Example

    Usage

    Como você pode ver na demonstração acima, o fornece IgrTreeGrid 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);
    }
    
    <IgrTreeGrid className="gridSize"></IgrTreeGrid>
    

    E agora vamos ver em detalhes como cada opção reflete no IgrTreeGrid componente. Quando você alterna entre diferentes opções de tamanho, a altura de cada IgrTreeGrid 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 IgrTreeGrid com o menor intenso e altura de linha igual a 50px. Os preenchimentos esquerdo e direito são 24px; A coluna width mínima é 80px;
    • Médio- Este é o tamanho médio intenso com 40px altura da linha. Os preenchimentos esquerdo e direito são 16px; A coluna width mínima é 64px;
    • Pequeno- Este é o tamanho com maior intensidade e 32px altura de linha. Os preenchimentos esquerdo e direito são 12px; A coluna width 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:

    <IgrPropertyEditorPanel
        ref={propertyEditorRef}
        componentRenderer={renderer}
        target={grid}
        descriptionType="WebTreeGrid"
        isHorizontal={true}
        isWrappingEnabled={true}>
        <IgrPropertyEditorPropertyDescription
            name="SizeEditor"
            label="Grid Size:"
            valueType="EnumValue"
            dropDownNames={["Small", "Medium", "Large"]}
            dropDownValues={["Small", "Medium", "Large"]}
            changed={webGridSetGridSize}>
        </IgrPropertyEditorPropertyDescription>
    </IgrPropertyEditorPanel>
    

    Agora podemos adicionar a marcação.

    <IgrTreeGrid autoGenerate={false} ref={treeGridRef} data={employeesFlatDetails} primaryKey="ID" foreignKey="ParentID" allowFiltering={true}>
        <IgrColumn field="Name" dataType="string" sortable={true} hasSummary={true} width="200"></IgrColumn>
        <IgrColumnGroup header="General Information">
            <IgrColumn field="HireDate" dataType="date" sortable={true} hasSummary={true}></IgrColumn>
            <IgrColumnGroup header="Personal Details">
                <IgrColumn field="ID" dataType="number" filterable={false}></IgrColumn>
                <IgrColumn field="Title" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
                <IgrColumn field="Age" dataType="number" sortable={true} hasSummary={true} filterable={false}></IgrColumn>
            </IgrColumnGroup>
        </IgrColumnGroup>
        <IgrColumnGroup header="Address Information">
            <IgrColumnGroup header="Location">
                <IgrColumn field="Country" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
                <IgrColumn field="City" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
                <IgrColumn field="Address" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
            </IgrColumnGroup>
            <IgrColumnGroup header="Contact Information">
                <IgrColumn field="Phone" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
                <IgrColumn field="Fax" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
                <IgrColumn field="PostalCode" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
            </IgrColumnGroup>
        </IgrColumnGroup>
    </IgrTreeGrid>
    

    Finalmente, vamos fornecer a lógica necessária para realmente aplicar o tamanho:

    private propertyEditor: IgrPropertyEditorPanel
    private propertyEditorRef(r: IgrPropertyEditorPanel) {
            this.propertyEditor = r;
            this.setState({});
    }
    private sizeEditor: IgrPropertyEditorPropertyDescription
    private grid: IgrTreeGrid
    private gridRef(r: IgrTreeGrid) {
        this.grid = r;
        this.setState({});
    }
    
    constructor(props: any) {
        super(props);
    
        this.propertyEditorRef = this.propertyEditorRef.bind(this);
        this.webGridSetGridSize = this.webGridSetGridSize.bind(this);
        this.gridRef = this.gridRef.bind(this);
    }
    
    private _componentRenderer: ComponentRenderer = null;
      public get renderer(): ComponentRenderer {
        if (this._componentRenderer == null) {
          this._componentRenderer = new ComponentRenderer();
          var context = this._componentRenderer.context;
          PropertyEditorPanelDescriptionModule.register(context);
          WebHierarchicalGridDescriptionModule.register(context);
        }
        return this._componentRenderer;
    }
    
    public webGridSetGridSize(sender: any, args: IgrPropertyEditorPropertyDescriptionChangedEventArgs): 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 IgrTreeGrid fornece para você, para poder alterar a altura das linhas no IgrTreeGrid, é a propriedade rowHeight. Então, vamos ver em ação como essa propriedade afeta o IgrTreeGrid 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 for rowHeight 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 IgrTreeGrid:

    <IgrTreeGrid className="gridSize" rowHeight="80px" width="100%" height="550px" allowFiltering={true}></IgrTreeGrid>
    

    API References

    Nossa comunidade é ativa e sempre acolhedora para novas ideias.