1. #1
    Ext GWT Premium Member
    Join Date
    Mar 2009
    Posts
    91
    Vote Rating
    0
    databass is on a distinguished road

      0  

    Default Best Practice for getting the value of a clicked cell in a grid

    Best Practice for getting the value of a clicked cell in a grid


    I have a listener which returns the values of each cell of a record clicked on a grid.

    The grid is bound to a store which contains a list of LabelValue objects. The LabelValue class consists of two getters: getLabel() and getValue().

    What I'm doing is working but it seems way too verbose. I'm still new at this...could someone possibly tell me if there's an easier way to do this?

    Thanks....

    Here's my code for the listener:

    accountDetailsBasicGrid.addListener(Events.CellClick, new Listener<GridEvent<ModelData>>() {

    public void handleEvent(GridEvent ge) {

    LabelValue labelValueRecord = (LabelValue) ((Grid) ge.getSource()).getStore().getAt(ge.getRowIndex());

    Window.alert("clicked label/value " + labelValueRecord.getLabel() + "/" + labelValueRecord.getValue());

    }
    });

  2. #2
    Sencha User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    867
    Vote Rating
    1
    micgala is on a distinguished road

      0  

    Default


    If I understood correctly, LabelValue is your Model class.

    You can change your code to this:
    Code:
    accountDetaisBasicGrid.addListener(Events.CellClick, new Listener<GridEvent<LabelValue>>() {
       public void handleEvent(GridEvent<LabelValue> be) {
          LabelValue model = be.getModel();
          Window.alert("clicked label/value " + model.getLabel() + "/" + model.getValue());
       }
    });
    Regards,
    Michel.

  3. #3
    Ext GWT Premium Member
    Join Date
    Mar 2009
    Posts
    91
    Vote Rating
    0
    databass is on a distinguished road

      0  

    Default


    Thanks for your reply. Yes, Label/Value is the Model class.

    I tried your suggestion, but this gives me a null pointer exception when I click on a value.

    Code:
    [ERROR] Uncaught exception escaped
    java.lang.NullPointerException: null
        at com.ssi.enquesta.gwt.inquiry.client.component.AccountDetailsComponent$1.handleEvent(AccountDetailsComponent.java:105)
        at com.ssi.enquesta.gwt.inquiry.client.component.AccountDetailsComponent$1.handleEvent(AccountDetailsComponent.java:1)
        at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:100)
        at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:455)
        at com.extjs.gxt.ui.client.widget.grid.Grid.onClick(Grid.java:568)
        at com.extjs.gxt.ui.client.widget.grid.Grid.onComponentEvent(Grid.java:366)
        at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:750)
        at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1320)
        at com.google.gwt.user.client.DOM.dispatchEventAndCatch(DOM.java:1299)
        at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1262)
        at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
        at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
        at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
        at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
        at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
        at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
        at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
        at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
        at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
        at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
        at com.google.gwt.dev.GWTShell.main(GWTShell.java:140)
    Quote Originally Posted by micgala View Post
    If I understood correctly, LabelValue is your Model class.

    You can change your code to this:
    Code:
    accountDetaisBasicGrid.addListener(Events.CellClick, new Listener<GridEvent<LabelValue>>() {
       public void handleEvent(GridEvent<LabelValue> be) {
          LabelValue model = be.getModel();
          Window.alert("clicked label/value " + model.getLabel() + "/" + model.getValue());
       }
    });
    Regards,
    Michel.

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    That will be fixed within the next release.

  5. #5
    Ext GWT Premium Member
    Join Date
    Mar 2009
    Posts
    91
    Vote Rating
    0
    databass is on a distinguished road

      0  

    Default


    Thanks. I'll stick with my workaround until then.

Thread Participants: 2