Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Unexpected behavior using a RecordClickHandler with an ListGridField

    Hello Everyone,

    First of all, I am currently using Smart GWT Version “6.0p”.

    What i have is a dropdown Grid that displays the reduced Data from the Datasource. (Somthing like this: http://www.smartclient.com/smartgwt/..._grid_category).
    I want to add a ClickHandler, so an Action (In the Test-Code "doSomeCoolStuff") can be executed using the Clicked Record.
    Also, I want the User to be able to use the Arrow Keys to navigate and execute the same Action using the "Enter" key.

    So far I added a "RecordClickHandler" to the "ListGridField" and if I click the Record, I can execute a Method to work with the Record input.
    But the "RecordClickHandler" also is executed when I am using the Arrow-Keys navigation through the Records.

    So my Questions are:
    1. Is there a RecordClickHandler, that only reacts, if the Record really is Clicked?
    2. How can I Accomplish using the Accow-Keys to navigate through the List Grid and Execute an action with the currently selected Record, using the "Enter"-Key?

    Test Project:
    I recreated this problem within this a Test Project. Therefore, I modified the "DataSourceDMI"-Sample Code of Smartgwt, to get a good Datasource.
    Also, I added the Click Handler like this: "itemField.addRecordClickHandler(event -> doSomeCoolStuff(event.getRecord()));"

    In this Test Code the same behavior as described earlier can be seen:
    I can reduce the Data and Click a Record to Execute the "doSomeCoolStuff" method.
    Also, I can navigate through the Grid list and Execute the Command using the "Enter"-Key.
    Till this point everything is what I want it to be.
    But I noticed that the Handler also executed the "doSomeCoolStuff" method every time I used the Arrow Keys to navigate.

    Code:
    Code:
    public class DataSourceDMI implements EntryPoint {
        public void onModuleLoad() {
            Layout layout = new VLayout();
            layout.setHeight100();
            layout.setWidth100();
    
            DataSource supplyItemDS = DataSource.get("supplyItemDMI");
              
            final DynamicForm form = new DynamicForm();  
            form.setWidth(300);  
      
            ListGridField itemField = new ListGridField("itemName");
            itemField.addRecordClickHandler(event -> doSomeCoolStuff(event.getRecord()));
            
            ListGridField unitsField = new ListGridField("units");  
            ListGridField unitCostField = new ListGridField("unitCost");  
      
            ComboBoxItem  item = new ComboBoxItem("itemID");  
            item.setWidth(240);  
            item.setTitle("Item");  
            item.setOptionDataSource(supplyItemDS);  
            item.setValueField("SKU");  
            item.setDisplayField("itemName");  
            item.setPickListWidth(450);  
            item.setPickListFields(itemField, unitsField, unitCostField);
            item.setCompleteOnTab(true);
            item.setShowTitle(false);
            item.setAutoFetchData(true);
            item.setMinimumSearchLength(3);
            item.setHideEmptyPickList(true);
      
            form.setItems(item);
      
            Layout layout = new Layout();
            layout.setWidth100();
            layout.setBorder("1px solid black");
            layout.setHeight("5%");
            layout.addMember(form);
            
    
            
            layout.draw();
        }
    
        public void doSomeCoolStuff(Record record) {
            GWT.log("Record Clicked: " + record.getAttributeAsString("itemName"));
        }
    }
    Thank you in advance!
    ~Jay

    #2
    You may use isc.EventHandler.getKey() inside recordClick to detect Arrow_Up, Arrow_Down, and Space key pressed.
    Then consider that the Enter key triggers the recordDoubleClick handler.

    Comment


      #3
      Thank you for the Response claudiobosticco!

      It was solved like this:

      Code:
              private Record tempSelectedSearchRecord;
              ...
      
              ListGrid searchFieldGrid = new ListGrid();
              ...
      
              searchFieldGrid.setSelectionType(SelectionStyle.SINGLE);
              searchFieldGrid.addCellClickHandler(event -> {
                  tempSelectedSearchRecord = null;
                  doSomeCoolStuff(event.getRecord());
              });
              searchFieldGrid.addSelectionChangedHandler(event -> tempSelectedSearchRecord = event.getRecord());
              searchFieldGrid.addBodyKeyPressHandler(event -> {
                  if ("Enter".equalsIgnoreCase(EventHandler.getKey()) && tempSelectedSearchRecord != null) {
                      doSomeCoolStuff(tempSelectedSearchRecord);
                      tempSelectedSearchRecord = null;
                  }
              });
      
              item.setPickListProperties(searchFieldGrid);
              ...

      But i still don't understand why a "RecordClickHandler" reacts to somethink that is no click.. does not make sense at all..

      Anyway. Thanks again for the Replay!
      ~Jay

      Comment

      Working...
      X