Results 1 to 3 of 3

Thread: [FIXED] EditorGrid problem with deleting last row

  1. #1

    Default [FIXED] EditorGrid problem with deleting last row

    Hi everyone, I am using new EditorGrid in GXT. And I have found the problem with deleting rows.
    First of all there is no sample code how to perform delete withing GXT samples.
    So I have created my own ColumnPlugin. It adds column with "Delete" buttons in cells.
    It works fine but not for deleting last row. When user deletes the last row, no other row could be deleted.
    The click on the first row for example, works fine and I can see that "Delete" button is not being activated by MouseClick, but after last row deletion any "Delete" button can be selected by MouseClick.
    The error stack:
    Code:
    [ERROR] Uncaught exception escaped
    com.google.gwt.core.client.JavaScriptException: (TypeError):Property or method is not supported by object
     number: -2146827850
     description: Объект не поддерживает это свойство или метод
        at com.google.gwt.dom.client.Element$.getElementsByTagName$(Native Method)
        at com.extjs.gxt.ui.client.widget.grid.GridView.getCell(GridView.java:271)
        at com.extjs.gxt.ui.client.widget.grid.GridView.onCellDeselect(GridView.java:1017)
        at com.extjs.gxt.ui.client.widget.grid.CellSelectionModel.deselectAll(CellSelectionModel.java:66)
        at com.extjs.gxt.ui.client.widget.grid.CellSelectionModel.selectCell(CellSelectionModel.java:98)
        at com.extjs.gxt.ui.client.widget.grid.CellSelectionModel.handleMouseDown(CellSelectionModel.java:110)
        at com.extjs.gxt.ui.client.widget.grid.CellSelectionModel.handleEvent(CellSelectionModel.java:83)
        at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:74)
        at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:423)
        at com.extjs.gxt.ui.client.widget.grid.Grid.onMouseDown(Grid.java:539)
        at com.extjs.gxt.ui.client.widget.grid.Grid.onComponentEvent(Grid.java:335)
        at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:655)
        at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308)
        at com.google.gwt.user.client.DOM.dispatchEventAndCatch(DOM.java:1287)
        at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1255)
    The code of Plugin:
    Code:
    import com.extjs.gxt.ui.client.Events;
    import com.extjs.gxt.ui.client.data.ModelData;
    import com.extjs.gxt.ui.client.event.GridEvent;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.widget.Component;
    import com.extjs.gxt.ui.client.widget.ComponentPlugin;
    import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
    import com.extjs.gxt.ui.client.widget.grid.ColumnData;
    import com.extjs.gxt.ui.client.widget.grid.Grid;
    import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
    
    public class ButtonDeleteColumnConfig extends ColumnConfig implements ComponentPlugin {
    
        protected Grid grid;
        private static final String DELETE_BUTTON_IMPL = "delete-button-impl-";
        private String name;
    
        public ButtonDeleteColumnConfig() {
            super();
        }
    
        public ButtonDeleteColumnConfig(String id, String name, int width) {
            super(id, name, width);
            this.name = name;
        }
    
        public void init(Component component) {
            this.grid = (Grid) component;
            grid.addListener(Events.CellMouseDown, new Listener<GridEvent>() {
                public void handleEvent(GridEvent e) {
                    onMouseDown(e);
                }
            });
            init();
        }
    
        protected void onMouseDown(GridEvent ge) {
            String cls = ge.getTarget().getClassName();
            if (cls != null && cls.indexOf(DELETE_BUTTON_IMPL + getId()) != -1) {
                ge.stopEvent();
                int index = grid.getView().findRowIndex(ge.getTarget());
                ModelData m = grid.getStore().getAt(index);
                grid.getStore().remove(m);
            }
        }
    
        protected void init() {
            setRenderer(new GridCellRenderer() {
                public String render(ModelData model, String property, ColumnData config, int rowIndex,
                                     int colIndex, ListStore store) {
                    return "<button class=\"gwt-Button " + DELETE_BUTTON_IMPL + getId() + "\" type=\"button\">" + name + "</button>";
                }
            });
        }
    }
    After adding a row to grid the "Delete" buttons work fine until last "Delete" button is not clicked.

    Thank you.

  2. #2
    Sencha User darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242

    Default

    This issue was previously fixed in SVN and will be available in the next relase. You code works fine with the latest code.

    Unrelated, all events fired by the Grid will have the rowIndex set. So you can do this:

    Code:
    protected void onMouseDown(GridEvent ge) {
            String cls = ge.getTarget().getClassName();
            if (cls != null && cls.indexOf(DELETE_BUTTON_IMPL + getId()) != -1) {
                ge.stopEvent();
                int index = ge.rowIndex; // get row index form event
                ModelData m = grid.getStore().getAt(index);
                grid.getStore().remove(m);
            }
        }

  3. #3

    Default

    Thank you for this quick response.
    One more question: does this bug appear for any grid or EditorGrid only?

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •