覆盖 CRM 网格中双击事件调用的标准方法.

CRM 2011 中的以下情况:我的目标是在一个网格中显示多个实体.因此,我们制作了一个链接到真实实体的包装实体(包装实体到实体 A、B、C).当创建 A、B 或 C 中的项目时,插件也会创建一个包装实体项目.像这样我可以有一个网格,混合"所有实体,而实际上只显示包装实体的项目.

Following situation in CRM 2011: My goal is to show several entities in one grid. Therefore we made a wrapper entity which links to the real entity (wrapper entity to entity A, B, C). When an item in A, B or C is created, also an wrapper entity item is created by a plugin. Like this I can have a grid, "mixing" all the entities, while in fact only show the items of the wrapper entity.

当然,如果我双击或右键单击->在此网格中打开,我不想打开包装实体项,我直接想打开例如窗口.实体 A 项.丝带按钮是没问题的顺便说一句.

But of course, if I do a double click or right click -> open in this grid, I don't want to open the wrapper entity item, I directly want to open the window of e.g. entity A item. Ribbon Button is no problem btw.

到目前为止,我遵循了两条路线:

I followed two routes so far:

a) 链接替换:加载网格后,我通过 DOM 并将 oid、otype 和 otypename 替换为(真实)目标项(实体 A、B 或 C)的值.这个想法有两个缺点:首先何时执行替换例程(仅在加载时还不够,因为它可能在以后排序、过滤或翻转页面).第二个问题是功能区按钮.我想删除包装实体项目,而不是它背后的发票.当我替换所有这些 ID 时,事情变得混乱.我将不得不用自定义按钮替换所有按钮.

a) Link replacement: After the grid is loaded I went through the DOM and replaced the oid, otype and otypename with the values of the (real) target item (entity A, B or C). This idea has a two downsides: first when to execute the replacement routine (only on load is not enough as its possible to sort, filter or flip pages later). Second and man problem are the ribbon buttons. I want to delete the wrapper entity items and not the invoice behind it. Things get confused when I replace all those IDs. I would have to replace all the buttons by custom buttons.

b) 方法/事件替换:只替换调用项目详细信息窗口的事件会很优雅.不幸的是,我还没有弄清楚这些事件是如何在 CRM 中实现的,我希望取消附加一个事件并用我的替换它,但这似乎是一个隐藏的秘密.CRMWeb_static_gridAppGrid_DefaultData.htc 有 dblclick-event,但我不明白这是否是我正在寻找的事件以及如何取消附加.

b) Method/Event replacement: it would be elegant to just replace the event where the item detail window is called. Unfortunately I didn't figure out yet how the events are implemented in CRM, I was hoping to unattach an event and replace it by mine, but this seems to be a hidden secret. CRMWeb_static_gridAppGrid_DefaultData.htc has the dblclick-event, but I don't understand if this is the one I'm looking for and how to unattach.

有没有人尝试过替换 crm 网格中的事件处理程序或知道它是如何工作的?

Has anyone ever tried to replace an event handler in a crm grid or got an idea how it might work?

希望我的意思很清楚......

Hope it's clear what I mean...

非常感谢您的任何想法.

Thank you very much for any idea.

推荐答案

界面中事件的处理方式与 IE 处理所有 javascript 事件(请参阅 SO 问题 我应该直接分配 JavaScript 事件来统一代码吗? 仅举一个例子).

Events in the interface are handled the same way IE handles all javascript events (see the SO question Should i assign JavaScript events directly just to unify code? for just one example).

覆盖默认双击操作的功能可能如下开始:

A functionality for overriding the default doubleclick action might start as follows:

function Load() {
    var grid = document.getElementById("myGridName");
    grid.ondblclick = DoubleClickAction;
}

function DoubleClickAction() {
    var id, url;
    //get the id of the entity in the row you double clicked
    id = GetId();

    //generate the entity form url
    url = GetUrl();

    //open the record window
    OpenRecordWindow(url);
}

function OpenRecordWindow(url) {
    var url;

    if (Xrm.Page.context.isOutlookClient()) {
        openStdWin(url, "Your Title", "width=1024,height=768,status=1");
    }
    else {
        window.open(url);
    }

}

<小时>

根据您的评论,您将在此处对 DOM 进行一些非常认真的自定义.您必须更改网格中每一行的 dblclick 事件每当网格刷新时,因为右键单击事件基于行的 dblclick 事件.因此,您必须找到网格并将 refresh 事件附加到将 dblclick 事件附加到任何找到的行的网格.


Based on your comments, you're getting into some pretty serious customization of the DOM here. You'd have to change the dblclick event for each row in the grid whenever the grid refreshes since the right click event is based on the row's dblclick event. So you'd have to find the grid and also attach a refresh event to the grid that attaches a dblclick event to any found rows.

要获取网格的 id 以及任何行的潜在 id,您可以使用 IE 的 F12 开发人员工具来浏览/搜索 HTML.

To get the id of the grid, and the potential ids of any rows, you can use IE's F12 developer tools to browse/search through the HTML.

相关文章