`
avi2
  • 浏览: 90341 次
社区版块
存档分类
最新评论

[转]GWT-Ext – Synchronized Scrolling of Grids

    博客分类:
阅读更多
I recently had a requirement wherein two grids showing similar information needed synchronized scrolling i.e. if the left grid was scrolled down vertically, the right grid also needed to be scrolled down in the same proportion and vice-versa.

This feature comes in very handy when the user has to compare the changed values across the two grids. Consider the use case of a user viewing his stock portfolio and wants to track the prices of his investments on two different dates.

The screenshot below explains the scenario:

In this scenario, we only need to the vertical scroll to be synchronized. However, if there is a horizontal scrollbar present, the horizontal scrolling would also be synchronized.

To implement synchronized scrolling follow the steps below:

1. Declare and initialize the grids:

//Create the right grid
final GridPanel rightGrid = new GridPanel();

//Create the left grid
final GridPanel leftGrid = new GridPanel();


2. Initialize two GridViews and attach them to the respective grids

//Right GridView
GridView gridViewRight = new GridView();
rightGrid.setView(gridViewRight);

//Left GridView
GridView gridViewLeft = new GridView();
leftGrid.setView(gridViewLeft);


3. Set other regular Grid properties like Column Model, Store etc.

4. Add a GridListener to each of the Grids. We only need to implement the onBodyScroll(int scrollLeft, int scrollTop) method of the listener so we will use GridListenerAdapter instead.

The GridView class provides a method
scrollToPosition(int horizontalPosition, int verticalPosition)
which scrolls the Grid scroll-bar to the specified position.
If the grid needs to be scrolled in only one of the direction, then pass the other position value as -1.

//Add a GridListener for the right grid that will
//scroll the left grid scroll bars when the right grid is scrolled.

rightGrid.addGridListener(new GridListenerAdapter(){
public void onBodyScroll(int scrollLeft, int scrollTop) {

//if the right grid scroll bar is moved,
//the left grid scroll bar needs to be moved proportionately

gridViewLeft.scrollToPosition(scrollLeft, scrollTop);
//gridViewLeft.scrollToPosition(-1, scrollTop);
}
});

//Add a GridListener for the left grid that will
//scroll the right scroll bars this grid is scrolled

leftGrid.addGridListener(new GridListenerAdapter(){
public void onBodyScroll(int scrollLeft, int scrollTop) {

//if the left grid scroll bar is moved,
//the right grid scroll bar needs to be moved proportionately

gridViewRight.scrollToPosition(scrollLeft, scrollTop);
//gridViewRight.scrollToPosition(-1, scrollTop);
}
});


That’s it! Now, whenever either of the grids is scrolled up or down, the other grid scroll bar would automatically adjust itself at the same position.

If you want only vertical scrolling to be synchronized, then comment the two lines and uncomment the commented lines in the listener code above.
[url]
http://jaydeepm.wordpress.com/2009/08/05/gwt-ext-synchronized-scrolling-of-grids/[/url]
分享到:
评论

相关推荐

    最好的gwt-ext学习资料

    ### Gwt-Ext:强大的网页开发控件库详解 Gwt-Ext,作为一个结合了Google Web Toolkit(GWT)和ExtJs的高级网页开发控件库,为纯Java语言的富互联网应用程序(RIA)开发提供了强有力的支持。尤其对于初学者而言,Gwt...

    Gwt-ext学习笔记之基础篇

    ### Gwt-ext学习笔记之基础篇 #### 一、安装CypalStudio工具 为了能够开始Gwt-ext的学习之旅,首先需要确保开发环境已经搭建好。CypalStudio是一款非常实用的工具,它能帮助开发者更高效地进行GWT项目的开发。 1....

    gwt-ext培训教程

    GWT-Ext是一个基于Google Web Toolkit (GWT)的JavaScript库,它提供了丰富的用户界面组件和强大的数据绑定机制,使得开发者能够构建出交互性强、视觉效果优秀的Web应用程序。本教程将深入探讨GWT-Ext的核心概念、...

    gwt-ext相关jar包及资源

    GWT-Ext是一个基于Google Web Toolkit (GWT)的用户界面库,它为开发者提供了丰富的JavaScript组件和功能,使得在GWT应用中构建复杂的、交互式的Web界面变得更加容易。GWT是一个由Google开发的开放源代码框架,允许...

    Gwt-Ext基础-中级-进阶

    Gwt-Ext是一种基于Google Web Toolkit (GWT)的JavaScript库,它扩展了GWT的功能,提供了丰富的用户界面组件和更美观的外观。这个压缩包包含的资源是关于Gwt-Ext的基础、中级和进阶学习资料,适合想要深入理解和应用...

    gwt-ext-tree

    6. **分页和无限滚动(Paging and Infinite Scrolling)**:对于包含大量数据的树,GWT-Ext-Tree 可以实现分页加载,只在需要时加载部分数据,提高页面性能。同时,无限滚动功能可以让用户在滚动时动态加载更多节点...

    Gwt-Ext学习笔记之进级篇

    在深入探讨GWT-Ext之前,我们先了解一下GWT(Google Web Toolkit)和Ext Js的基础。GWT是一个开源的开发工具,允许开发者使用Java语言来编写客户端的Web应用程序,然后将其编译为优化过的JavaScript代码,以实现高...

    gwt-ext 实例

    2. **引入gwt-ext到项目**:如何在Maven或Gradle构建系统中添加gwt-ext依赖,以及在GWT模块配置文件(.gwt.xml)中启用gwt-ext库。 3. **创建UI组件**:使用gwt-ext库创建各种组件,如Grid、FormPanel、ComboBox等...

    Gwt-ext学习笔记

    GWT(Google Web Toolkit)和Ext JS是两个在Web开发领域广泛应用的技术,它们结合形成的Gwt-ext库,为开发者提供了一种构建富客户端应用程序的强大工具。这篇学习笔记将深入探讨Gwt-ext的核心概念、功能以及如何在实际...

    GWT-EXT2.0最佳实践教程,源代码打包供下载

    《GWT-EXT2.0最佳实践教程》源代码打包下载资源主要涵盖了Google Web Toolkit (GWT) 和EXT-JS 2.0的结合使用,提供了丰富的实践案例和示例代码,旨在帮助开发者深入理解和应用这两项技术。GWT是一款强大的JavaScript...

    非常好的gwt-ext培训教程

    【GWT-Ext 知识点详解】 GWT-Ext 是一个高级的网页开发控件库,它结合了 Google Web Toolkit (GWT) 和 ExtJs 的优势,为开发者提供了丰富的 UI 组件和强大的功能。GWT 是一个由 Google 开发的用于构建富互联网应用...

    GWT-Ext_体验之旅.doc

    【GWT-Ext 知识点详解】 GWT-Ext 是一个基于 Google Web Toolkit (GWT) 和 ExtJS 的开源控件库,专为构建富互联网应用程序(RIA)提供强大的功能。它允许开发者使用纯 Java 语言进行界面开发,极大地提高了开发效率。...

    GWT-Ext超级Widget功能类库

    GWT-Ext超级Widget功能类库是一个基于Google Web Toolkit (GWT)的扩展库,它为开发者提供了丰富的用户界面组件和强大的功能,旨在提升Web应用的用户体验和开发效率。GWT是一个开源框架,允许Java开发者使用Java语言...

    Gwt-Ext学习笔记之基础篇- www.hxiaseo.cn技术网站

    标题中的"Gwt-Ext学习笔记之基础篇"指的是关于Gwt-Ext的初级教程,这是一种基于Google Web Toolkit (GWT) 的扩展库,用于构建富互联网应用程序(RIA)。Gwt-Ext提供了丰富的用户界面组件,使得开发者可以利用Java语言...

    GWT-Ext 控件演示

    GWT-Ext 控件演示 GWT-Ext 控件演示

    (转载)GWT -EXT学习笔记-基础

    ### GWT-EXT基础知识详解 #### 一、GWT与GWT-EXT简介 Google Web Toolkit (GWT) 是一款由Google开发的开源框架,它允许开发者使用Java语言编写前端应用,并将其编译成浏览器可识别的JavaScript和HTML。GWT提供了...

    需要GWT-Ext 2.0.5来下

    GWT-Ext 2.0.5 has been released. Grab the distribution from the Downloads area. GWT-Ext 2.0.5 supports GWT 1.5 final (1.5.2), Firefox3 and Chrome.

Global site tag (gtag.js) - Google Analytics