View Full Version : Getting the grid to respond to pasted text (post-paste processing)

18 Apr 2011, 3:50 PM
I'm having a problem where we've got a grid with editable cells (we extended EditorSupport). As part of our app, we have to be able to handle text folks paste into cells via CTRL-V, and then do some post-processing (paste from a spreadsheet, so we have to parse the actual text, then figure out how to jigger the model to reflect what the pasted text is supposed to be).

The problem comes in that our business users want this to happen with just CTRL-V. I can get it to parse the text properly if the users navigate away from the cell via ENTER, TAB, etc - that triggers the onEditComplete() method of our extended EditorSupport class. But, that doesn't get triggered by just pasting. If you add a listener to the editor's text field, it doesn't seem to have the ability to signal the edit event is complete.

Any ideas? I'm fairly new to GXT, and these requirements are pretty inflexible ("It should work just like Excel"), so I'm trying to work around them

Thanks in advance,


21 Apr 2011, 9:02 AM
We got it figured out - we extended TextField for the editor, and added some logic as shown below. We listen for two events - ONPASTE, and a subsequent ONKEYUP. That lets the browser complete the paste event, and then we can parse the pasted text (we're pasting from a spreadsheet) to figure out what cells to add.

The code in our extended TextField looks like this:

private boolean isPaste; //keep track of whether we're in a paste event

OrderGridField(OrderGridViewModel viewModel) // contructor for our class
this.viewModel = viewModel;
sinkEvents(ONPASTE); // this tells the dom we're interested in events

public void onBrowserEvent(Event event)
String rawValue = getRawValue();
String originalValue1 = getOriginalValue();


if (event.getTypeInt() == Event.ONPASTE) // handle a paste event - if we tried to process the text right now,
// the browser wouldn't have handled it yet. So, we have to wait
isPaste = true; //set the paste flag to true

if ((event.getTypeInt() == Event.ONKEYUP) && isPaste) // We have a key up after a paste event - now the text has been pasted and is available for parsing
viewModel.parsePaste(rawValue, editor.row, editor.col); //call the model to handle the pasted text (which will paste into other cells as well as this one)
isPaste = false; // unset the paste flag