Skip to main content
All docs
V24.1

Column Layout Specifics in Blazor TreeList

  • 9 minutes to read

The column layout in the TreeList depends on the component’s total width, column widths, borders, and cell spacing. The following code snippets demonstrate how the component is rendered in different scenarios:

All Column Widths Are Unspecified

If you do not specify column widths, the TreeList component renders columns with equal widths (but not less than the MinWidth value) and wraps content if needed. If a column’s MinWidth value is greater than the calculated column width, the TreeList applies the specified minimum width to this column and splits the remaining space between the rest of the columns.

In the following example, all column widths are 700 px / 4 = 175 px, which is greater than the default MinWidth value (50 px):

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: 700px;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate> 
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - Column Widths Are Not Specified

Several Column Widths Are Unspecified

If the TreeList component contains both columns with unspecified and specified widths, the web browser applies specified column widths first. Columns without specified widths occupy the remaining width in equal shares (but not less than the MinWidth value).

In the following code snippet, the web browser applies Name and Type column widths first. The remaining 700 px - 225 px - 125 px = 350 px are divided between Mass and Radius columns equally (350 px / 2 = 175 px).

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: 700px;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="225" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="125" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn> 
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - Several Column Widths Are Not Specified

Column Widths Are Specified in Different Units

The TreeList component can contain columns whose widths are specified in absolute units, while other column widths are specified in percentages. In this case, the web browser applies column widths specified in absolute units first. Then the TreeList component calculates remaining column widths as specified percentages of the TreeList’s total width (but not less than the MinWidth value).

In the following code snippet, the web browser applies Name and Type column widths first (225 px and 125 px). Then the component calculates remaining column widths (700 px * 0.25 = 175 px).

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: 700px;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="225" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="125" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="25%">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" Width="25%"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - Column Widths Are Specified in Different Units

After calculations, if the total column width is less than the TreeList’s width, an empty space remains to the right. If the total column width exceeds the TreeList’s width, the TreeList recalculates column widths specified in percentages relative to the remaining space as follows: SpecifiedColumnWidthInPercentages / SumOfAllPercentages * TreeListRemainingWidthInPixels.

In the following example, the sum of all column widths in percentages is 100%. The TreeList calculates column widths relative to this value. For instance, the Mass column’s width is 25% / 100% * (700 px - 120 px) = 145 px.

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: 700px;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="50%" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="120" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="25%">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" Width="25%"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - The Total Width in Percentages Exceeds Total Width

A column’s width cannot be less than the MinWidth property value. Set this property to 0 for a column whose width is specified in percentages to collapse this column when there is not enough space to display it.

The Total Column Width in Pixels Exceeds the TreeList’s Width

The default width of the TreeList component is 100% of its container width. You can assign a CSS class to the component to change its width value. The component displays the horizontal scrollbar if the sum of all column widths in pixels (considering the MinWidth value) is greater than the TreeList’s total width.

In the following example, the sum of column widths is 750 px, which is greater than the TreeList’s total width of 700 px:

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: 700px;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="300" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="200" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="200">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        @* The following column's width equals MinWidth (50px) *@
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" />
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - The Total Column Width in Pixels Exceeds TreeList's Width

If you clear the TreeList’s width attribute value (for example, set it to unset), the component fills the container to display all columns:

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: unset;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="300" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="200" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="200">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        @* The following column's width is based on the container's width but not less than the MinWidth *@
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" />
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - The Total TreeList Width is Not Set

The Total Column Width in Pixels is Less Than the TreeList’s Width

If the sum of all specified column widths is less than the TreeList’s width, an empty space remains to the right. In the following example, the sum of column widths is 650px, which is less than the TreeList’s total width of 950px:

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<style>
    .my-class {
        width: 950px;
    }
</style>

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites" CssClass="my-class">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="200" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="150" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="150">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" Width="150"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - Several Column Widths Are Not Specified

The Total Column Width in Percentages Exceeds 100%

If the sum of all relative widths is greater than 100%, the component reduces these values proportionally so that the sum of percentages equals 100%.

In the following example, the sum of all column widths is 150%. The TreeList component reduces column widths relative to this value. For instance, the Name column’s width is 60% of the 150%, but it would be 40% of the TreeList’s total width.

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="60%" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="30%" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="30%">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" Width="30%"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - Total Column Width Exceeds than 100%

The Total Column Width in Percentages is Less Than 100%

If the sum of all column widths in percentages is less than 100%, an empty space remains to the right. The following example sets the total column width to 85%:

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<DxTreeList Data="TreeListData" ChildrenFieldName="Satellites">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Width="40%" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="15%" />
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" Width="15%">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" Width="15%"/>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
}

TreeList Layout Specifics - Total Column Width is Less than 100%