React Tamanho da grade
O recurso Ignite UI for React Tamanho no React Grid permite que os usuários controlem o espaçamento e o layout dos dados dentro doIgrGrid. Ao mudar--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 Exemplo de Tamanho da Grade
Uso
Como você pode ver na demonstração acima, eleIgrGrid oferece três opções de tamanho: pequeno, médio e grande. O trecho de código abaixo mostra como definir--ig-size uma classe inline ou parte de uma classe CSS:
.gridSize {
--ig-size: var(--ig-size-medium);
}
<IgrGrid className="gridSize"></IgrGrid>
E agora vamos ver em detalhes como cada opção reflete oIgrGrid componente. Quando você alterna entre diferentes opções de tamanho, a altura de cadaIgrGrid elemento e os acolchoamentos correspondentes serão alterados. Além disso, se quiser aplicar colunaswidth personalizadas, considere que ela deve ser maior do que a soma do preenchimento à esquerda e à direita:
- Grande- Este é o tamanho padrão
IgrGridcom o menor intenso e a altura da linha iguais a50px. Os acolchoamentos à esquerda e à direita são24px: Colunawidthmínima é80px; - Médio- Este é o tamanho médio intenso com
40pxaltura de fileira. Os acolchoamentos à esquerda e à direita são16px: Colunawidthmínima é64px; - Pequeno- este é o tamanho com maior intensidade e
32pxaltura de fileira. Os acolchoamentos à esquerda e à direita são12px: Colunawidthmínima é56px;
[! Nota] Por favor, tenha em mente que atualmente você não pode substituir nenhum dos tamanhos.
Vamos agora continuar com nossa amostra e ver em ação como o--ig-size é aplicado. Vamos primeiro adicionar um botão que nos ajude a alternar entre cada tamanho:
<IgrPropertyEditorPanel
ref={propertyEditorRef}
componentRenderer={renderer}
target={grid}
descriptionType="WebGrid"
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.
<IgrGrid autoGenerate={false} ref={gridRef} data={invoicesData} allowFiltering={true}>
<IgrColumn field="CustomerName" header="Customer Name" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="Country" header="Country" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="City" header="City" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="Address" header="Address" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="PostalCode" header="Postal Code" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="Salesperson" header="Sales Person" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ShipperName" header="Shipper Name" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="OrderDate" header="Order Date" dataType="date" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ProductID" header="ID" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ProductName" header="Name" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="UnitPrice" header="Unit Price" dataType="number" sortable={true} hasSummary={true} filterable={false}></IgrColumn>
<IgrColumn field="Quantity" header="Quantity" dataType="number" sortable={true} hasSummary={true} filterable={false}></IgrColumn>
<IgrColumn field="Discontinued" header="Discontinued" dataType="boolean" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ShipName" header="Name" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ShipCountry" header="Country" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ShipCity" header="City" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
<IgrColumn field="ShipPostalCode" header="Postal Code" dataType="string" sortable={true} hasSummary={true}></IgrColumn>
</IgrGrid>
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: IgrGrid
private gridRef(r: IgrGrid) {
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 queIgrGrid permite mudar a altura das fileirasIgrGrid é a propriedaderowHeight. Então, vamos ver em ação como essa propriedade afeta oIgrGrid layout junto com o--ig-size.
Lembre-se do seguinte:
--ig-sizeA variável CSS não terá impacto na altura da linha se forrowHeightespecificada.--ig-sizeafetará todos os outros elementos da Grade, como foi descrito acima.
Agora podemos estender nossa amostra e adicionarrowHeight propriedades aoIgrGrid:
<IgrGrid className="gridSize" rowHeight="80px" width="100%" height="550px" allowFiltering={true}></IgrGrid>
Referências de API
Recursos adicionais
- Virtualização e desempenho
- Edição
- Paginação
- Filtragem
- Classificação
- Resumos
- Fixação de coluna
- Redimensionamento de colunas
- Escolha
- Procurando
Nossa comunidade é ativa e sempre acolhedora para novas ideias.