GWT Cell Table Clicking on a new row gives value of Previously selected row -


in gwt 2.6 celltable, i'm writing single click event perform operation. can not correct row index while clicking on celltable row; double click event returns row correctly.

final singleselectionmodel<patientdto> selectionmodel =      new singleselectionmodel<patientdto>();  patientstable.setselectionmodel(selectionmodel);    patientstable.adddomhandler(new clickhandler()   {       @override       public void onclick(clickevent event)       {         patientdto selected = selectionmodel.getselectedobject();         if (selected != null)          {             rootlayoutpanel.get().clear();             rootlayoutpanel.get().add(new patientpanel(selected));         }     } }, clickevent.gettype()); 

either use singleselectionmodel or multiselectionmodel , add selectionchangehandler on fired when selection changed in celltable

sample code:

final singleselectionmodel<contact> selectionmodel = new singleselectionmodel<contact>(); //final multiselectionmodel<contact> selectionmodel = new multiselectionmodel<contact>(); selectionmodel.addselectionchangehandler(new selectionchangeevent.handler() {      @override     public void onselectionchange(selectionchangeevent event) {         set<contact> selected = selectionmodel.getselectedset();         if (selected != null) {             (contact contact : selected) {                 system.out.println("you selected: " + contact.name);             }         }     } }); 

or alternatively try cellpreviewhandler

table.addcellpreviewhandler(new handler<contact>() {      @override     public void oncellpreview(cellpreviewevent<contact> event) {         int row = event.getindex();         int column = event.getcolumn();          if ("focus".equals(event.getnativeevent().gettype())) {            //..         }         if ("blur".equals(event.getnativeevent().gettype())) {             //...         }         if ("mousedown".equals(event.getnativeevent().gettype())) {             //..         }         if ("mouseover".equals(event.getnativeevent().gettype())) {             //..         }     }  }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -