Announcement

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

    ListGrid restraining focus on the top row

    Be sure your post includes:

    HI,
    1. I am using SmartGWT version as below:
    SmartClient Version: v8.3p_2013-01-12/LGPL Development Only (built 2013-01-12)

    2. Browser is firefox 12.0 (Mozilla firefox for Ubuntu)

    Requirement:
    I am using a ListGrid, which is grouped by one of the fields. (I am using the showcase example http://www.smartclient.com/smartgwt/showcase/#grid_grouping_modes, which is grouped by hemisphere).

    If the selection focus on the 1st row of a grouped listgrid, and up arrow is pressed again, I want the focus to still remain in ths first row. But the default behavior seems to be that the grid focus moves beyond the first row (probably to the grouped record) and hence no focus is shown.

    My requirement is that the selection focus remain on the first record, even if user tries to go beyond 1st record.

    To achieve this, I added the following code to the listgrid:keydownhandler after downloading the showcase sample http://www.smartclient.com/smartgwt/showcase/#grid_grouping_modes

    Code:
    	countryGrid.addKeyDownHandler(new KeyDownHandler() {
    			
    			@Override
    			public void onKeyDown(KeyDownEvent event) {
    				GWT.log("Key down:" + EventHandler.getKey());
    				final String key = EventHandler.getKey();
    				Integer row = countryGrid.getFocusRow();
    				if ((row=countryGrid.getFocusRow())==1 && key.equals("Arrow_Up"))
    					countryGrid.selectRecord(row);
    			}
    		});
    But this didn't achieve what I wanted, and the behavior is the same.

    I also tried overriding the bodykeypresshandler for listgrid
    Code:
    		countryGrid.addBodyKeyPressHandler(new BodyKeyPressHandler() {
    			@Override
    			public void onBodyKeyPress(BodyKeyPressEvent event) {
    				final String key = EventHandler.getKey();
    				Integer row = countryGrid.getFocusRow();
    				if ((row=countryGrid.getFocusRow())==1 && key.equals("Arrow_Up"))
    					countryGrid.selectRecord(row);
    			}
    		});
    This also didn't work.

    Thanks to anyone pointing out to me a way of achieving this.

    @isomorphic,

    This can be simulated by the showcase example cited above.

    Thanks in advance for all the help.
    Ravindra

    #2
    I "think" I hit a bug?

    @Isomorphic,

    After some more R&D, I added a line of code event.cancel() to keyDownHandler and updated as below.

    Code:
    			public void onKeyDown(KeyDownEvent event) {
    				GWT.log("Key down:" + EventHandler.getKey());
    				final String key = EventHandler.getKey();
    				Integer row = countryGrid.getFocusRow();
    				GWT.log("Focus row: " + row);
    				if (row==1 && key.equals("Arrow_Up")) {
    					countryGrid.selectRecord(row);
    					event.cancel();
    				}
    This fix apparently seemed to solve the problem.

    Continuing ahead, I tried to add END key handler to focus on the last row (the grid has a fixed number of rows (about 15), so finding and focusing on last row is not a penalty).

    But then a weird behavior has surfaced. For example, if the current focus on a middle row (say 7th row), hitting the End key moves the focus to the last (15) row as expected. After this, if Up key is pressed, the expectation is to see the focus on (last -1 ) row i.e 14th.

    But the focus is shown on 6th row i.e. one less than the previous 7th row.

    Is this behavior is a bug? Can you kindly verify? This is easily simulatable in the showcase example cited earlier.

    Note that, adding /removing the event.cancel() for end key handling has no effect on this behavior.


    regards,
    Ravindra
    Attached Files

    Comment


      #3
      Thanks to anyone helping me out with getting this focussing stuff right.

      Comment

      Working...
      X