React Tree Grid Size
The Ignite UI for React Size feature in React Tree Grid allows users to control the spacing and layout of data within the IgrTreeGrid
. By changing --ig-size
, you can significantly improve the user experience when interacting with large amounts of content. They can choose from three size options:
--ig-size-large
--ig-size-medium
--ig-size-small
React Tree Grid Size Example
Usage
As you can see in the demo above, the IgrTreeGrid
provides three size options: small, medium and large. The code snippet below shows how to set --ig-size
either inline or part of a CSS class:
.gridSize {
--ig-size: var(--ig-size-medium);
}
<IgrTreeGrid className="gridSize"></IgrTreeGrid>
And now let's see in details how each option reflects on the IgrTreeGrid
component. When you switch between different size options the height of each IgrTreeGrid
element and the corresponding paddings will be changed. Also if you want to apply custom column width
, please consider the fact that it must be bigger than the sum of left and right padding.
- large - this is the default
IgrTreeGrid
size with the lowest intense and row height equal to50px
. Left and Right paddings are24px
; Minimal columnwidth
is80px
; - medium - this is the middle intense size with
40px
row height. Left and Right paddings are16px
; Minimal columnwidth
is64px
; - small - this is the size with highest intense and
32px
row height. Left and Right paddings are12px
; Minimal columnwidth
is56px
;
[!Note] Please keep in mind that currently you can not override any of the sizes.
Let's now continue with our sample and see in action how the --ig-size
is applied. Let's first add a button which will help us to switch between each size:
<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>
Now we can add the markup.
<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>
Finally, let's provide the necessary logic in order to actually apply the size:
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})`);
}
Another option that IgrTreeGrid
provides for you, in order to be able to change the height of the rows in the IgrTreeGrid
, is the property rowHeight
. So let's see in action how this property affects the IgrTreeGrid
layout along with the --ig-size
.
Please keep in mind the following:
--ig-size
CSS variable will have no impact on row height if there isrowHeight
specified.--ig-size
will affect all of the rest elements in the Tree Grid, as it has been described above.
We can now extend our sample and add rowHeight
property to the IgrTreeGrid
:
<IgrTreeGrid className="gridSize" rowHeight="80px" width="100%" height="550px" allowFiltering={true}></IgrTreeGrid>
API References
Our community is active and always welcoming to new ideas.