blazor-devexpress-dot-blazor-dot-dxtreelist-a28d9209.md
Adjusts column width to content.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public void AutoFitColumnWidths()
DxTreeList uses the fixed table layout algorithm to render HTML, and column widths never depend on the column content - the component does not adjust column width based on column content automatically. Refer to the following topics for additional information on how Blazor TreeList renders its columns:
If you allow column resize in the UI, users can double-click a column’s right border to apply the optimal width (best fit) based on the column’s content (that is, cell content of visible columns, headers, and summaries).
You can call the AutoFitColumnWidths() method to adjust column widths to their content in code.
Note
The AutoFitColumnWidths method has no effect if column virtualization is enabled.
The best fit algorithm uses the same units as the column’s Width property value:
Depending on the calculated values, the following outcomes are possible:
The following example calls the AutoFitColumnWidths method to calculate initial optimal column widths. The algorithm sets Task and Employee Name column widths in pixels, and in percentages for the remaining columns:
<DxTreeList @ref="TreeList" Data="Data" KeyFieldName="Id" ParentKeyFieldName="ParentId">
<Columns>
<DxTreeListDataColumn FieldName="Name" Caption="Task" Width="100px" />
<DxTreeListDataColumn FieldName="EmployeeName" Width="100px"/>
<DxTreeListDataColumn FieldName="StartDate" />
<DxTreeListDataColumn FieldName="DueDate" />
</Columns>
</DxTreeList>
@code {
ITreeList TreeList { get; set; }
List<EmployeeTask> Data { get; set; }
protected override void OnInitialized() {
Data = EmployeeTaskService.GenerateData();
}
protected override void OnAfterRender(bool firstRender) {
if(firstRender) {
TreeList.AutoFitColumnWidths();
}
}
}
See Also