Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

javascript - Override standard method called by double click event in CRM grid.

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.

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) 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) 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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Events in the interface are handled the same way IE handles all 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);
    }

}

Edit: 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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...