有没有办法在模型驱动应用中动态筛选子网格?

huangapple go评论64阅读模式
英文:

Is there any way to Filter a Sub Grid Dynamically in Model Driven App

问题

我在表单中有一个子网格,在那里,我需要根据表的另一个字段的数据来过滤列。我一直尝试使用JavaScript来实现这一点,但不确定出现了错误"undefined"。尝试了很多方法,但没有帮助。

var conSubGrid = Xrm.Page.getControl("Subgrid_new_9");
conSubGrid.setFilterXml("<filter><condition attribute=’cr85c_Nameid’ operator=’eq’ value=’ABCD’ /></filter>");
conSubGrid.refresh();

我能够获取当前网格的详细信息,但无法设置筛选条件。
任何帮助将不胜感激,提前致谢。

英文:

I am having Sub-Grid in a Form where, I need to filter a Column as per the data from other feild of a table. I have been trying to achieve this using Java Script but not sure getting the error an "undefined". Tried out many way but nothing has helped.

var conSubGrid = Xrm.Page.getControl(&quot;Subgrid_new_9&quot;);
conSubGrid.setFilterXml(&quot;&lt;filter&gt;&lt;condition attribute=’cr85c_Nameid’ operator=’eq’ 
value=’ABCD’ /&gt;&lt;/filter&gt;&quot;);
conSubGrid.refresh();

I am able to fetch the Current Grid Details but not able to Set the filter Criteria.
Any help will be appreciated, thanks in advance.

答案1

得分: 1

请注意,setFilterXml是subgrid的一个未记录的JavaScript API,因此将来可能会出现可能的弃用或删除。

根据其他论坛中提供的示例,您必须将整个fetchXML传递给setFilterXml,而不仅仅是filterxml。

> 更新:修改下面的函数以获取fetchXml,并修改以附加filterxml并设置FetchXml并刷新

function SubGridFilterExecution(executionContext) {
    
    var formContext = executionContext.getFormContext();
    
    var gridContext = formContext.getControl("Subgrid_new_9");
    
    var fetchXml = gridContext.getFetchXml();
    
    fetchXml = fetchXml.replace("</entity>", "<filter><condition attribute='cr85c_Nameid' operator='eq' value='ABCD' /></filter></entity>");
    
    gridContext.setFilterXml(fetchXml);
    
    gridContext.refresh();
}

来源链接:https://www.crmcrate.com/javascript/dynamics-365-crm-filter-the-sub-grid-dynamically-with-javascript/

英文:

Please note that setFilterXml is an undocumented javascript api for subgrid so there might be possible deprecation or removal of this api in future.

As per the samples avaialable in other forums you have to pass the whole fetchXML in the setFilterXml and not just the filterxml.

> Update: modified below function to get fetchXml and modify to append
> the filterxml and setFetchXml & Refresh

function SubGridFilterExecution(executionContext) {

    var formContext = executionContext.getFormContext();

    var gridContext = formContext.getControl(&quot;Subgrid_new_9&quot;);

    var fetchXml = gridContext.getFetchXml();

    fetchXml = fetchXml.replace(&quot;&lt;/entity&gt;&quot;, &quot;&lt;filter&gt;&lt;condition attribute=&#39;cr85c_Nameid&#39; operator=&#39;eq&#39; value=&#39;ABCD&#39; /&gt;&lt;/filter&gt;&lt;/entity&gt;&quot;);

    gridContext.setFilterXml(fetchXml);

    gridContext.refresh();
}

https://www.crmcrate.com/javascript/dynamics-365-crm-filter-the-sub-grid-dynamically-with-javascript/

huangapple
  • 本文由 发表于 2023年6月14日 23:30:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定