TreeList 中的排序、过滤和自定义模板列

发布于 2025-01-15 08:14:31 字数 1767 浏览 3 评论 0原文

我在列上使用 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>

更新片段: https://blazorrepl.telerik.com/mQuxlWkD32B5eGay33

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹊巢 2025-01-22 08:14:31

确保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 the FieldType, or set it to the type of the Owner field, not to a different field.

终难愈 2025-01-22 08:14:31

您是否确实希望将列绑定到您希望比较所基于的基础基元类型,而不是 Avatar 对象本身?为此,您需要将 FieldFieldType 参数更新为适当的嵌套属性和类型。

我创建了一个 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 the Field and FieldType 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文