DxTreeList.Data Property
Specifies a data source.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v25.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(null)]
[Parameter]
public object Data { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Object | null | A data source. |
Remarks
Bind TreeList to Data
Use the Data
property to bind the TreeList component to a data source that implements the IEnumerable or IListSource interface. Initialize this data source in the OnInitialized or OnInitializedAsync lifecycle method. Refer to the following topic for more information: Bind Blazor TreeList to Data.
Note
The TreeList component does not support binding to fields with the same name for different types.
The following example binds the TreeList component to a flat data source:
@inject EmployeeTaskService EmployeeTaskService
<DxTreeList Data="TreeListData" KeyFieldName="Id" ParentKeyFieldName="ParentId">
<Columns>
<DxTreeListDataColumn FieldName="Name" Caption="Task" />
<DxTreeListDataColumn FieldName="EmployeeName" />
<DxTreeListDataColumn FieldName="StartDate" />
<DxTreeListDataColumn FieldName="DueDate" />
</Columns>
</DxTreeList>
@code {
List<EmployeeTask> TreeListData { get; set; }
protected override void OnInitialized() {
TreeListData = EmployeeTaskService.GenerateData();
}
}
Reload Data
The TreeList component automatically reloads data in response to the following actions:
- Observable Data Collection Notification
- You can bind the TreeList to a data collection that implements the INotifyCollectionChanged or IBindingList interface. These collections notify the TreeList about changes and cause automatic updates. For more information, refer to the following help topic: Observable Data Collections.
- Data Instance Change
- If you change an instance of a field/property bound to the
Data
parameter, the TreeList reloads its data in response to this change. You can use this technique if you post updates to the underlying service (such as DbContext EF Core). - Editing-Related Events
- You can allow users to edit TreeList data. To process user input and save changes, handle EditModelSaving and DataItemDeleting events. The TreeList reloads its data after the corresponding event handler is executed. For more information, refer to the following help topic: Edit Model in Blazor TreeList.
In other cases, call the Reload() method after the TreeList’s bound data source is changed. The method gets updated data from the source and applies changes to the TreeList.