简体   繁体   中英

How to handle the finishing of changing the value in the grid cell in GXT2

I have an app with GXT. In this app there is a grid in which I need to edit values in cells. I create cells in this way:

column = new ColumnConfig();
fieldEditor = new CellEditor(new TextField<String>());
column.setEditor(fieldEditor);
column.setId("value");
column.setHeader("Value");
column.setWidth(650);
configs.add(column);

As you see I use TextField as an editor. so, after I change the value I can press Enter or click in any other place of the window. how to handle this. I tried to handle ButtonPress event and MouseClick event, but this drops an exception or don't do anything.

UPD: NOw I'm trying to implement this in the following way:

valueEditor = new TextField<String>();
KeyListener keyListener = new KeyListener(){
    @Override
    public void componentKeyUp(ComponentEvent event){
        if (event.getKeyCode() == KeyCodes.KEY_ENTER){
        if (valueEditor.getValue() != null && !("").equals(valueEditor.getValue())){
           Window.alert("Enter Button Pressed");
           PropertyItem item;
           item = new PropertyItem(grid.getStore().getAt(rowNumber).getName(),                 
                grid.getStore().getAt(rowNumber).getType(), valueEditor.getValue(),    
                grid.getStore().getAt(rowNumber).isAccepted());
           store.update(item);
           store.commitChanges();
           saveProperties(store, customerId, toRemove);
                    }
                }
            }
        };
        valueEditor.addKeyListener(keyListener);

and what is the problem: it doesn't handle the Enter press in the end of editing, but only handle it after the editing deactivated.

If you want to handle enter event on TextField than you can used following code

TextField<String> field = new TextField<String>();
KeyListener keyListener = new KeyListener(){
    @Override
    public void componentKeyUp(ComponentEvent event) {
        if(event.getKeyCode() == KeyCodes.KEY_ENTER){
            //do stuff
        }
    }
};
field.addKeyListener(keyListener);

column = new ColumnConfig();
fieldEditor = new CellEditor(field);
column.setEditor(fieldEditor);
column.setId("value");
column.setHeader("Value");
column.setWidth(650);
configs.add(column);

if it's not help to you than you can used focus lost event. hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM