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

取消选择子网格记录时如何移除关联SubGrid的筛选条件?

解决取消SubGrid记录选择后筛选条件未清除的问题

原代码的问题在于取消选中记录时,仅调用了表单整体刷新,并未清除目标SubGrid的筛选规则,导致筛选条件残留。需要修改取消选中分支的逻辑,直接操作SubGrid控件清除筛选。

修改后的完整代码

function subgridOnSelect(executionContext) {
    var selected = executionContext.getFormContext().data.entity;
    var Id = selected.getId();
    var formContext = window.ALLCONTEXT;
    
    if(Id != undefined && Id != null) {
        addSubgridEventListener(Id, formContext);
    } else {
        // 替换原表单刷新,改为清除SubGrid筛选
        clearSubgridFilter(formContext);
    }
}

function addSubgridEventListener(recordid, formContext) {
    var gridContext = formContext.getControl("subgrid_teamstemplatechannelfolders");
    if (gridContext == null) {
        setTimeout(function () { addSubgridEventListener(recordid, formContext); }, 500);
        return;
    }

    var fetchxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                    "  <entity name='sis_teamstemplatechannelfolder'>" +
                    "    <attribute name='sis_channelnameid' />" +
                    "    <attribute name='sis_foldermembergroupid' />" +
                    "    <attribute name='sis_foldername' />" +
                    "    <attribute name='sis_parentfolderid' />" +
                    "    <attribute name='sis_teamstemplatechannelfolderid' />" +
                    "    <order attribute='sis_foldername' descending='false' />" +
                    "    <filter type='and'>" +
                    "      <condition attribute='sis_channelnameid' operator='eq' value='"+recordid+"' uiname='Teams Template Channel Test 1' uitype='sis_teamstemplatechannel' />" +
                    "    </filter>" +
                    "  </entity>" +
                    "</fetch>";

    gridContext.setFilterXml(fetchxml);
    gridContext.refresh();
}

// 新增清除SubGrid筛选的函数
function clearSubgridFilter(formContext) {
    var gridContext = formContext.getControl("subgrid_teamstemplatechannelfolders");
    if (gridContext == null) {
        setTimeout(function () { clearSubgridFilter(formContext); }, 500);
        return;
    }
    // 设置空的filterXml移除筛选,再刷新SubGrid
    gridContext.setFilterXml("");
    gridContext.refresh();
}

var ALLCONTEXT;
function Onload(executionContext) {
    ALLCONTEXT = executionContext.getFormContext();
}

关键改动说明

  • 将原else分支的formContext.data.refresh()替换为调用clearSubgridFilter函数,直接针对目标SubGrid操作
  • clearSubgridFilter函数复用了SubGrid加载检测逻辑,确保控件就绪后,通过setFilterXml("")清除筛选规则,再调用refresh()刷新SubGrid,彻底移除残留的筛选条件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 23:53:10