Announcement

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

    Dynamically setting ScrollPosition on ListGrid

    Hi guys,

    I'm using SmartGWT 2.2 and I have been trying to find a way to set the scroll position of a ListGrid dynamically. I found this post: http://forums.smartclient.com/showthread.php?p=41594#post41594

    and used some of the code, which works nicely for initial setting of the scroll position. Problem is I'm using a Filter with the ListGrid and I want to reset the scroll position to 0 everytime the filter is called or reset. It works properly if it hasn't saved a scroll position before that. It saves the scroll position only upon clicking on an object from the listGrid. If I have clicked on an object the position is saved, I refresh the page and the listGrid scrolls down to the object I had chosen before, then I click the filter buttons and it sorts out the data, but sets my scrollposition to some random number. Here is how my code is at the moment and it doesn't seem to work:

    Code:
    private String scrollPos = cookieUtil.getProjectsTableScrollPosition();
    public ProjectsListPage() {
    
    public void refresh() {
    
    //....
    
    filterButton = new IButton("Filter");
    		filterButton.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
                            saveFilterState();
    		        listGrid.filterData(ListFilters.getCriteria());
    			CookieUtil.getDefault().setProjectsTableScrollPosition(null);
    			listGrid.scrollToRow(0);
    			}
    		});
    
    filterClearButton = new IButton("Reset");
    	filterClearButton.addClickHandler(new ClickHandler() {
    		@Override
    		public void onClick(ClickEvent event) {
    		   filters.clearCriteria();
    		   saveFilterState();
    		   listGrid.filterData(filters.getCriteria());
    		   CookieUtil.getDefault().setProjectsTableScrollPosition(null);
    		   listGrid.scrollToRow(0);}});
    
    //....
    
    listGrid.addDataArrivedHandler(handler = new DataArrivedHandler() {
    		@Override
    		public void onDataArrived(DataArrivedEvent event) {
    		if (!(scrollPos.equals(null)) && !(scrollPos.equals("-1"))) {
    			DeferredCommand.addCommand(new Command() {
    			@Override
    			public void execute() {
    				int i = Integer.parseInt(scrollPos);
    				listGrid.scrollToRow(i);
    			}
    		});
    		}
    		else {
    		DeferredCommand.addCommand(new Command() {
    			@Override
    			public void execute() {
    			     listGrid.scrollToRow(0);
    			}
    		});
    		}
    	}});
     }
    
    
    private void saveFilterState() {
    
    //...
    
      CookieUtil.getDefault().setProjectsTableScrollPosition(null);
      listGrid.scrollToRow(0);
      }
    }
    Putting debug messages I've found out that the DataArrivedHandler is not being called when the Filter buttons are being pushed

    Thanks in advance.

    Regards,
    Ilian
Working...
X