Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
818
Popup Hides Under Main Window Solution
posted

I have been struggling with a situation for years now in which windows opened in new windows from links in the grid are opened behind the window the grid resides in because the grid tries to take the focus back. After much digging and theorizing, I have finally devised a fairly simple, but not at all obvious solution to the problem that I feel compelled to share.

There are actually two cases that need to be resolved. The first solution, which is to cancel the grid's MouseUp event covers all but the first time a link is clicked after a document is opened. The first time a link is clicked, the onmouseup event on the cell does not appear to be fired, so you have to clear an undocumented flag on the grid in order to get the desired behavior.

Here is the code that I use, in which I make sure the clicked column is one that I am interested in before implementing the behavior:


function ugDocuments_MouseUpHandler(gridName, id, button){
    // For the download and view columns, cancel the standard mouseup event
    // because if this is not done, focus will be returned to the grid through
    // a window.setTimeout event
    var oCell = igtbl_getCellById(id);
    if (oCell != null) {
        switch (oCell.Column.Key.toLowerCase()) {
            case "downloadcolumn":
            case "viewcolumn":
                return true;
                break;
        }
    }
}

var m_fFirstTime = 1;
function ugDocuments_MouseDownHandler(gridName, id, button){
    // The first time this event is fired for the download or view column,
    // the _mouseDown property on the grid needs to be cleared because the mouseup
    // event is not fired for some strange reason. This will ensure the popup window
    // that is opened for the hyperlink is not opened behind the other windows.
    if (m_fFirstTime == 1) {
        var oCell = igtbl_getCellById(id);
        if (oCell != null) {
            switch (oCell.Column.Key.toLowerCase()) {
                case "downloadcolumn":
                case "viewcolumn":
                    m_fFirstTime = 0;
                    oCell.Band.Grid._mouseDown = 0;
                    break;
            }
        }
    }
}