React Hierarchical Grid Size
The Ignite UI for React Size feature in React Hierarchical Grid allows users to control the spacing and layout of data within the IgrHierarchicalGrid
. 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 Hierarchical Grid Size Example
Usage
As you can see in the demo above, the IgrHierarchicalGrid
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);
}
<IgrHierarchicalGrid id="grid" className="gridSize">
</IgrHierarchicalGrid>
And now let's see in details how each option reflects on the IgrHierarchicalGrid
component. When you switch between different size options the height of each IgrHierarchicalGrid
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
IgrHierarchicalGrid
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="WebHierarchicalGrid"
isHorizontal="true"
isWrappingEnabled="true">
<IgrPropertyEditorPropertyDescription
name="SizeEditor"
label="Grid Size:"
valueType="EnumValue"
dropDownNames={["Small", "Medium", "Large"]}
dropDownValues={["Small", "Medium", "Large"]}
changed={this.webGridSetGridSize}>
</IgrPropertyEditorPropertyDescription>
</IgrPropertyEditorPanel>
Now we can add the markup.
<IgrHierarchicalGrid
autoGenerate="false"
ref={this.grid}
id="grid"
allowFiltering="true">
<IgrColumn field="CustomerID" dataType="String"></IgrColumn>
<IgrColumn field="CompanyName" dataType="String"></IgrColumn>
<IgrColumn field="ContactName" dataType="String"></IgrColumn>
<IgrColumn field="Address" dataType="String"></IgrColumn>
<IgrColumn field="City" dataType="String"></IgrColumn>
<IgrColumn field="PostalCode" dataType="String"></IgrColumn>
<IgrColumn field="Country" dataType="String"></IgrColumn>
<IgrColumn field="Phone" dataType="String"></IgrColumn>
<IgrColumn field="Fax" dataType="String"></IgrColumn>
<IgrRowIsland childDataKey="Orders" autoGenerate="false">
<IgrColumn field="OrderID" dataType="Number"></IgrColumn>
<IgrColumn field="EmployeeID" dataType="Number"></IgrColumn>
<IgrColumn field="OrderDate" dataType="Date"></IgrColumn>
<IgrColumn field="RequiredDate" dataType="Date"></IgrColumn>
<IgrColumn field="ShippedDate" dataType="Date"></IgrColumn>
<IgrColumn field="ShipVia" dataType="Number"></IgrColumn>
<IgrColumn field="Freight" dataType="Number"></IgrColumn>
<IgrColumn field="ShipName" dataType="String"></IgrColumn>
<IgrColumn field="ShipAddress" dataType="String"></IgrColumn>
<IgrColumn field="ShipCity" dataType="String"></IgrColumn>
<IgrColumn field="ShipPostalCode" dataType="String"></IgrColumn>
<IgrColumn field="ShipCountry" dataType="String"></IgrColumn>
<IgrRowIsland childDataKey="OrderDetails" autoGenerate="false">
<IgrColumn field="ProductID" dataType="Number"></IgrColumn>
<IgrColumn field="UnitPrice" dataType="Number"></IgrColumn>
<IgrColumn field="Quantity" dataType="Number"></IgrColumn>
<IgrColumn field="Discount" dataType="Number"></IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
</IgrHierarchicalGrid>
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: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
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 IgrHierarchicalGrid
provides for you, in order to be able to change the height of the rows in the IgrHierarchicalGrid
, is the property rowHeight
. So let's see in action how this property affects the IgrHierarchicalGrid
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 Hierarchical Grid, as it has been described above.
We can now extend our sample and add rowHeight
property to the IgrHierarchicalGrid
:
<IgrHierarchicalGrid id="grid" className="gridSize" rowHeight="80px" width="100%" height="550px" allowFiltering="true">
</IgrHierarchicalGrid>
API References
Our community is active and always welcoming to new ideas.