TreeList 中的排序、过滤和自定义模板列
我在列上使用 TreeList 和自定义模板来显示用户头像。我还需要对此列进行排序和过滤。但是,当在模板列上组合所有这些功能(排序和过滤)时,它不起作用。有 2 个问题:
禁用排序时,过滤不起作用
启用排序时,过滤起作用,但排序抛出错误:“无法比较数组中的两个元素。” -->此问题已解决,如下评论。
有没有解决这个问题的解决方案?我正在使用 Blazor 3.0.1 的 UI
<TelerikTreeList Data="@Tasks"
IdField="Id"
ParentIdField="ParentId"
Sortable="true"
SortMode="@SortMode.Single"
FilterMode="@TreeListFilterMode.FilterMenu">
<TreeListColumns>
@*when disable sort, the filtering doesnt work*@
<TreeListColumn Field="Owner" FieldType="@typeof(Avatar)" Title="Owner" Sortable="false"
FilterMenuType="@FilterMenuType.CheckBoxList">
<Template>
@{
var item = context as TaskItem;
<MyAvatar Avatar="item.Owner"></MyAvatar>
}
</Template>
</TreeListColumn>
@*when enable sort, the filter works but the sorting throw error*@
<TreeListColumn Field="Owner" FieldType="@typeof(Avatar)" Title="Owner" Sortable="true"
FilterMenuType="@FilterMenuType.CheckBoxList">
<Template>
@{
var item = context as TaskItem;
<MyAvatar Avatar="item.Owner"></MyAvatar >
}
</Template>
</TreeListColumn>
</TreeListColumns>
</TelerikTreeList>
I am using TreeList and a custom template on a column to display user avatar. I also need to sort and filter on this column. However when combine all of these features (sort and filter) on a template column, it doesn't work. There are 2 issues:
When disable sort, the filtering doesnt work
When enable sort, the filtering works but the sorting throw error: "Failed to compare two elements in the array." --> This issue is already resolved as below comment.
Is there any work around solution for this? I am using UI for Blazor 3.0.1
<TelerikTreeList Data="@Tasks"
IdField="Id"
ParentIdField="ParentId"
Sortable="true"
SortMode="@SortMode.Single"
FilterMode="@TreeListFilterMode.FilterMenu">
<TreeListColumns>
@*when disable sort, the filtering doesnt work*@
<TreeListColumn Field="Owner" FieldType="@typeof(Avatar)" Title="Owner" Sortable="false"
FilterMenuType="@FilterMenuType.CheckBoxList">
<Template>
@{
var item = context as TaskItem;
<MyAvatar Avatar="item.Owner"></MyAvatar>
}
</Template>
</TreeListColumn>
@*when enable sort, the filter works but the sorting throw error*@
<TreeListColumn Field="Owner" FieldType="@typeof(Avatar)" Title="Owner" Sortable="true"
FilterMenuType="@FilterMenuType.CheckBoxList">
<Template>
@{
var item = context as TaskItem;
<MyAvatar Avatar="item.Owner"></MyAvatar >
}
</Template>
</TreeListColumn>
</TreeListColumns>
</TelerikTreeList>
Updated snipped: https://blazorrepl.telerik.com/mQuxlWkD32B5eGay33
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保
Field
名称是原始(值)类型而不是完整对象。这是用于过滤和排序的模型字段。然后,删除FieldType
,或将其设置为Owner
字段的类型,而不是其他字段。Make sure that the
Field
name is a primitive (value) type and not a full object. This is the field of the model used for filter and sort. Then, either remove theFieldType
, or set it to the type of theOwner
field, not to a different field.您是否确实希望将列绑定到您希望比较所基于的基础基元类型,而不是
Avatar
对象本身?为此,您需要将Field
和FieldType
参数更新为适当的嵌套属性和类型。我创建了一个 REPL 片段来演示这一点(请注意,我添加了一些虚拟类,因为它们在初始片段中缺失): https://blazorrepl.telerik.com/mQuxlWkD32B5eGay33
Could it be that you actually want to bind the columns to the underlying primitive type you would like the comparison to be based on, rather than the
Avatar
object itself? To do that, you would like to update theField
andFieldType
parameters to the appropriate nested property and type.I've created a REPL snippet that demonstrates this (note I've added some dummy classes as they were missing from the initial snippet): https://blazorrepl.telerik.com/mQuxlWkD32B5eGay33