You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Kentico树视图的列表界面?两项定制需求

修改Kentico树视图列表界面的实现方案

1. 为特定页面类型设置默认Page type筛选

可以通过注册文档列表事件实现仅针对特定页面类型的默认筛选,不会影响全局设置。在项目的Global.asax.cs或自定义模块代码中添加以下逻辑:

using CMS.DocumentEngine;
using CMS.PortalEngine;
using System;

protected void Application_Start()
{
    // 注册文档列表列加载后的事件
    DocumentListEvents.GetColumns.After += SetDefaultPageTypeFilter;
}

private void SetDefaultPageTypeFilter(object sender, DocumentListEventArgs e)
{
    // 替换为你的目标页面类型类名,比如"MySite.CustomPage"
    string targetPageType = "MySite.CustomPage";
    if (string.Equals(e.NodeClassName, targetPageType, StringComparison.OrdinalIgnoreCase))
    {
        // 设置默认筛选的Page type值为当前页面类型
        e.DefaultFilterValues["documenttype"] = targetPageType;
    }
}

这段代码会在加载指定页面类型的树视图列表时,自动将Page type筛选器默认选中为该类型,其他页面类型不受影响。

2. 移除"Show all levels"复选框

有两种常用方式实现:

方式一:自定义CSS隐藏

在Kentico后台进入设置 -> 站点 -> 你的站点 -> 外观 -> 自定义CSS,添加以下样式:

/* 全局移除树视图中的Show all levels复选框 */
.tree-view-show-all-levels {
    display: none !important;
}

如果仅需针对特定页面类型隐藏,使用更精准的选择器:

/* 仅针对MySite.CustomPage类型的列表隐藏 */
.page-type-MySite_CustomPage .tree-view-show-all-levels {
    display: none !important;
}

注意页面类型类名中的点号会被转换为下划线,所以选择器中用MySite_CustomPage。

方式二:通过UI元素配置修改

  1. 进入系统 -> 模块 -> 内容管理 -> UI元素
  2. 搜索并找到Document list - Tree view这个UI元素
  3. 编辑该元素,在"元素属性"中找到对应"Show all levels"复选框的配置项,将其设置为隐藏
  4. 若需针对特定页面类型,可在页面类型的列表界面配置中,自定义移除该控件

内容的提问来源于stack exchange,提问作者chamara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 21:22:38