TreeListCustomSortEventArgs Class
Contains data for the CustomSort event.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
public class TreeListCustomSortEventArgs
Remarks
Follow the steps below to implement custom logic used to sort data in the DxTreeList.
- Set the SortMode property to
Custom
. Handle the CustomSort event to implement your logic that compares column values. When the event fires, the component compares two row values: the Value1 and Value2 properties. To define the column’s sort algorithm, set the Result property to one of the following values:
Value Description -1
The TreeList places the first data item above the second item in ascending sort mode and below the second item in descending sort mode. 1
The TreeList places the first data item below the second item in ascending sort mode and above the second item in descending sort mode. 0
Indicates that the data items are equivalent according to the comparison condition. The TreeList sorts them based on their indices in the data source. Set the Handled property to
true
to indicate that the current comparison operation is handled. If the value is set tofalse
, the component ignores the result of the custom comparison and uses the default mechanism to compare item values.
The following code snippet implements custom logic to sort the Start Date column’s values without taking into account the year part of the date:
@inject EmployeeTaskService EmployeeTaskService
<DxTreeList Data="TreeListData" KeyFieldName="Id" ParentKeyFieldName="ParentId" CustomSort="OnCustomSort">
<Columns>
<DxTreeListDataColumn FieldName="Name" Caption="Task" />
<DxTreeListDataColumn FieldName="EmployeeName" />
<DxTreeListDataColumn FieldName="StartDate"
DisplayFormat="d"
SortIndex="0"
SortMode="TreeListColumnSortMode.Custom"/>
<DxTreeListDataColumn FieldName="DueDate" />
</Columns>
</DxTreeList>
@code {
List<EmployeeTask> TreeListData { get; set; }
protected override void OnInitialized() {
TreeListData = EmployeeTaskService.GenerateData();
}
void OnCustomSort(TreeListCustomSortEventArgs e) {
if (e.FieldName == "StartDate") {
var date1 = Convert.ToDateTime(e.Value1);
var date2 = Convert.ToDateTime(e.Value2);
if (date1.Month == date2.Month)
e.Result = date1.Day.CompareTo(date2.Day);
else
e.Result = date1.Month.CompareTo(date2.Month);
e.Handled = true;
}
}
}