Announcement

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

    Why is ListGrid.getSelectedState() always null?

    (SmartGWT 1.2, the very first day+night with SmartGWT)

    I need to reset selection on ListGrid. So I checked what does getSelectedState() return when nothing (no rows/records) is selected,
    and I tried to pass that value to setSelectedState() when I need to reset the selection... But nothing changed.
    I have noticed that the getSelectedState() method returns null even when a row is selected.

    (I read somewhere that selectedState may be sensitive to whether data from DataSource has arrived already or not.
    But at this moment I define the data manually, my ListGrid is not connected to any DataSource, so I assume this is not the case.)

    Javadoc does not hint anything special about selectedState:
    http://www.smartclient.com/smartgwt/...tedState%28%29

    What am I doing wrong please?

    Code:
    // table/grid {
    
    ListGrid grid = new ListGrid();
    grid.setShowHeaderContextMenu(false);
    grid.setSelectionType(SelectionStyle.SINGLE);
    
    // when user clicks on the grid store id of the selected service
    grid.addRowMouseUpHandler(new RowMouseUpHandler()
      {
        public void onRowMouseUp(RowMouseUpEvent event)
        {
          Record selectedRecord = grid.getSelectedRecord();
          Integer serviceId = selectedRecord == null ? null : selectedRecord.getAttributeAsInt("id");
          setServiceId(serviceId);
    
          // let's see... {
          System.out.println(serviceId); // actually prints actual 'id' attribute (checked)
          System.out.println(grid.getSelectedState()); // _always_ null :(
          // }
        }
      });
    
    // define fields {
    
    TreeGridField idField = new TreeGridField("id", 25);
    TreeGridField titleField = new TreeGridField("title", 150);
    grid.setFields(idField, titleField);
    
    // }
    
    // define data {
    
    RecordList recordList = new RecordList();
    
    Record record;
    
    record = Record.getOrCreateRef(JavaScriptObject.createObject());
    record.setAttribute("id", 1);
    record.setAttribute("title", "service A");
    recordList.add(record);
    
    record = Record.getOrCreateRef(JavaScriptObject.createObject());
    record.setAttribute("id", 2);
    record.setAttribute("title", "service B");
    recordList.add(record);
    
    record = Record.getOrCreateRef(JavaScriptObject.createObject());
    record.setAttribute("id", 3);
    record.setAttribute("title", "service C");
    recordList.add(record);
    
    grid.setData(recordList);
    
    // }
    
    // place the grid into GWT VerticalPanel
    vPanel.add(grid);
    So far I 'reset' the selection by resetting the data.

    #2
    Possibly by "reset" you mean deselecting all records, if so, call deselectAllRecords().

    Comment


      #3
      Originally posted by Isomorphic
      Possibly by "reset" you mean deselecting all records, if so, call deselectAllRecords().
      oh snap... yes, that is what i need, thanks a lot!!

      best regards
      Jarda

      Comment


        #4
        i am fall the same issue with you, did you resolve the problem

        Comment

        Working...
        X