Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Interactive Grid how to enable cell highlight and copy functionality

Bruce ClarkJun 2 2017 — edited Jun 2 2017

Hello friends;

I am using Apex 5.1 and have an Interactive Grid that I am using simply as a report (no DML). In the past, when I used IRs, the user was able to highlight the value from a cell and copy if to say a text item or to another app such as notepad etc.  With IGs that are no in edit mode, this does not seem to be available functionality. Is there a way that I can enable this functionality?

Any help, as always, is greatly appreciated.

Kind regards,

Bruce

Comments

John Snyders-Oracle

Hi Bruce,

The grid view of Interactive Grid disables text selection on purpose. There are technical reasons why the mousedown event, which starts the text selection, is handled the way it is to prevent the default in some cases. But there is a logical justification as well. Because IG grid view supports selection (meaning the current row or rows are in a selected state) it doesn't support text selection. This is consistent with a multi line select list (<select size=10>...). You will note that selecting one or more items in a select list and pressing Ctrl+C does not copy what you have selected also you can not select parts of the text in a select list. The idea in both cases is that the control is letting you work with the data at a higher level than just text.

But what you or your users are trying to do is not unreasonable and others have asked for the same thing. I think it has come up on the forums before. In the future I hope that IG grid will support copy in a meaningful way.

In the mean time you could go back to using IR if this is an important use case or you could take matters into your own hands and do something like the following:

Add an event handler for the copy event. This handler should be on the body or document. I used a DA

Event: Custom

Custom Event: copy

Selection Type: jQuery Selector

jQuery Selector: body

Then add one JavaScript true action with this code:

// this handler must be on the body or document to work in chrome

var text, i, selection, gridSel;

var event = this.browserEvent.originalEvent; // need the clipboard event

// we only care about copy from a grid cell ignore the rest

if ( !$(document.activeElement).hasClass("a-GV-cell") ) {

    return;

}

var view = apex.region("emp").widget().interactiveGrid("getCurrentView"); // change "emp" to you IG static id

if ( view.internalIdentifier === "grid") {

    text = "";

    selection = window.getSelection();

    gridSel = view.view$.grid("getSelection");

    for (i = 0; i < gridSel.length; i++) {

        selection.selectAllChildren(gridSel[i][0]);

        text += selection.toString();

        if (gridSel[i].length > 1) {

            selection.selectAllChildren(gridSel[i][1]);

            text += " \t" + selection.toString();

        }

        text += "\r\n";

    }

    selection.removeAllRanges();

    event.clipboardData.setData('text/plain', text);

    event.preventDefault();

}

The above will copy the current grid selection to the clipboard when the user types Ctrl+C while in a grid cell.

The selection and clipboard events and APIs are not final standards yet so there may be some cross browser issues. I have tested this on Firefox and Chrome in Windows.

There are many possibilities here. If you just want the text of the current cell then replace the loop over the grid selection with something like:

window.getSelection().selectAllChildren(document.activeElement);

Regards,

-John

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 30 2017
Added on Jun 2 2017
1 comment
9,144 views