-
关于gwt-ext grid 的问题25
我在界面上添加了两个grid,其中一grid1显示数据库表test1中的内容,双击grid1某一行,根据双击grid1某一行某一列的数据,按条件检索数据库表test2中的数据,并在grid2中显示出来。各位大大这个功能如何实现???
问题补充:
谢谢楼上,我想我用的是服务端与客户端通信,我的现在定义了如下方法
1、已定义好impl中的queryData()方法,客户端能正常调用
public class InfoListActionImpl extends RemoteServiceServlet implements
private static final long serialVersionUID = 3340062097368093852L;
public String[][] queryData(){
String[][] allInfo = null;
String query = "select 材料名称,规格型号,计量单位,期末库存,期末库存金额 from 设备仓库库存情况表 where 期末库存>0 order by 材料名称,规格型号";
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
String URL = "jdbc:jtds:sqlserver://127.0.0.1:1433/db_wzgl;USER=sa;PASSWORD=sa";
Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(query);
int i = 0;
int rows = 0;
if (rs.last()){
rows = rs.getRow();
rs.beforeFirst();
}
ResultSetMetaData rsm = rs.getMetaData();
int columns = rsm.getColumnCount();
allInfo = new String[rows][columns];
while (rs.next()) {
for (int j = 0; j < columns; j++){
allInfo[i][j] = rs.getString(j + 1);
}
i++;
}
rs.close();
stmt.close();
conn.close();
}catch (ClassNotFoundException e) {
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return allInfo;
}
2、定义了async接口
public interface InfoListActionAsync {
public void queryData(AsyncCallback<String[][]> callback);
}
3、客户端脚本
public class InfoList implements EntryPoint {
private GridPanel grid;
private GridPanel grid1;
//@SuppressWarnings("unchecked")
public void onModuleLoad() {
InfoListActionAsync action = InfoListAction.Util.getInstance();
action.queryData(new AsyncCallback() {
public void onFailure(Throwable caught) {
}
public void onSuccess(Object result) {
Panel panel = new Panel();
panel.setBorder(false);
panel.setPaddings(15);
RecordDef recordDef = new RecordDef(new FieldDef[] {
new StringFieldDef("材料名称"),
new StringFieldDef("规格型号"),
new StringFieldDef("计量单位"),
new StringFieldDef("期末库存"),
new StringFieldDef("期末库存金额") });
String[][] data = (String[][]) result;
MemoryProxy proxy = new MemoryProxy(data);
ArrayReader reader = new ArrayReader(recordDef);
final Store store = new Store(proxy, reader,false);
ColumnConfig clmcColumn = new ColumnConfig("材料名称", "材料名称", 220, false);
clmcColumn.setAlign(TextAlign.CENTER);
ColumnConfig ggxhColumn = new ColumnConfig("规格型号", "规格型号", 400, false);
ggxhColumn.setAlign(TextAlign.CENTER);
ColumnConfig jldwColumn = new ColumnConfig("单位", "计量单位", 60, false);
jldwColumn.setAlign(TextAlign.CENTER);
ColumnConfig qmkcColumn = new ColumnConfig("数量", "期末库存", 110, false);
qmkcColumn.setAlign(TextAlign.CENTER);
ColumnConfig qmkcjeColumn = new ColumnConfig("金额", "期末库存金额", 150, false);
qmkcjeColumn.setAlign(TextAlign.CENTER);
ColumnModel columnModel = new ColumnModel(new ColumnConfig[]{
clmcColumn,
ggxhColumn,
jldwColumn,
qmkcColumn,
qmkcjeColumn
});
grid = new GridPanel();
grid.setHeight(400);
grid.setWidth(975);
grid.setTitle("库存明细查询");
grid.setStore(store);
grid.setColumnModel(columnModel);
grid.setTrackMouseOver(false);
grid.setLoadMask(true);
grid.setSelectionModel(new RowSelectionModel());
grid.setFrame(true);
grid.setStripeRows(true);
grid.setIconCls("grid-icon");
Toolbar topToolbar = new Toolbar();
topToolbar.addFill();
grid.setTopToolbar(topToolbar);
GridSearchPlugin gridSearch = new GridSearchPlugin(GridSearchPlugin.TOP);
gridSearch.init(grid);
gridSearch.setMode(GridSearchPlugin.LOCAL);
grid.addPlugin(gridSearch);
store.load();
panel.add(grid);
RecordDef recordDef1 = new RecordDef(new FieldDef[] {
new StringFieldDef("仓库名称"),
new StringFieldDef("库存数量"),
new StringFieldDef("库存金额"),
new StringFieldDef("当月消耗"),
new StringFieldDef("消耗金额") });
String[][] data1 = null;
data1 = new String[1][5];
MemoryProxy proxy1 = new MemoryProxy(data1);
ArrayReader reader1 = new ArrayReader(recordDef1);
final Store store1 = new Store(proxy1, reader1,false);
ColumnConfig clmcColumn1 = new ColumnConfig("仓库名称", "仓库名称", 320, false);
clmcColumn1.setAlign(TextAlign.CENTER);
ColumnConfig ggxhColumn1 = new ColumnConfig("库存数量", "库存数量", 110, false);
ggxhColumn1.setAlign(TextAlign.CENTER);
ColumnConfig jldwColumn1 = new ColumnConfig("库存金额", "库存金额", 200, false);
jldwColumn1.setAlign(TextAlign.CENTER);
ColumnConfig qmkcColumn1 = new ColumnConfig("当月消耗", "当月消耗", 110, false);
qmkcColumn1.setAlign(TextAlign.CENTER);
ColumnConfig qmkcjeColumn1 = new ColumnConfig("消耗金额", "消耗金额", 200, false);
qmkcjeColumn1.setAlign(TextAlign.CENTER);
ColumnModel columnModel1 = new ColumnModel(new ColumnConfig[]{
clmcColumn1,
ggxhColumn1,
jldwColumn1,
qmkcColumn1,
qmkcjeColumn1
});
grid1 = new GridPanel();
grid1.setHeight(160);
grid1.setWidth(975);
grid1.setStore(store1);
grid1.setColumnModel(columnModel1);
grid1.setTrackMouseOver(false);
grid1.setLoadMask(true);
grid1.setSelectionModel(new RowSelectionModel());
grid1.setFrame(true);
grid1.setStripeRows(true);
grid.addGridRowListener(new GridRowListener(){
public void onRowDblClick(GridPanel grid, int rowIndex, EventObject e){
store1.load();
}
public void onRowClick(GridPanel grid, int rowIndex, EventObject e){
}
public void onRowContextMenu(GridPanel grid, int rowIndex, EventObject e){
}
});
panel.add(grid1);
RootPanel.get().add(panel);
}
});
}
}
问题是我如何在定义并调用一个带参数的queryData1()查询方法,根据前台onRowDblClick事件双击的某一行莫一列的数据检索数据库,并将数据返回前台。
不胜感谢!!!!
问题补充:
我已经在服务端定义了一个querydata1方法并在onRowDblClick成功调用,但是代码很繁琐,各位能不能给优化优化,下面是我的从新写得客户端代码:
public class InfoList implements EntryPoint {
private GridPanel grid;
private GridPanel grid1;
//@SuppressWarnings("unchecked")
public void onModuleLoad() {
final InfoListActionAsync action = InfoListAction.Util.getInstance();
action.queryData(new AsyncCallback() {
public void onFailure(Throwable caught) {
}
public void onSuccess(Object result) {
Panel panel = new Panel();
panel.setBorder(false);
panel.setPaddings(15);
/*Button iconButton = new Button("执行查询", new ButtonListenerAdapter() {
public void onClick(Button button, EventObject e) {
}
});
panel.add(iconButton);*/
RecordDef recordDef = new RecordDef(new FieldDef[] {
new StringFieldDef("材料名称"),
new StringFieldDef("规格型号"),
new StringFieldDef("计量单位"),
new StringFieldDef("期末库存"),
new StringFieldDef("期末库存金额") });
String[][] data = (String[][]) result;
MemoryProxy proxy = new MemoryProxy(data);
ArrayReader reader = new ArrayReader(recordDef);
final Store store = new Store(proxy, reader,false);
ColumnConfig clmcColumn = new ColumnConfig("材料名称", "材料名称", 220, false);
clmcColumn.setAlign(TextAlign.CENTER);
ColumnConfig ggxhColumn = new ColumnConfig("规格型号", "规格型号", 400, false);
ggxhColumn.setAlign(TextAlign.CENTER);
ColumnConfig jldwColumn = new ColumnConfig("单位", "计量单位", 60, false);
jldwColumn.setAlign(TextAlign.CENTER);
ColumnConfig qmkcColumn = new ColumnConfig("数量", "期末库存", 110, false);
qmkcColumn.setAlign(TextAlign.CENTER);
ColumnConfig qmkcjeColumn = new ColumnConfig("金额", "期末库存金额", 150, false);
qmkcjeColumn.setAlign(TextAlign.CENTER);
ColumnModel columnModel = new ColumnModel(new ColumnConfig[]{
clmcColumn,
ggxhColumn,
jldwColumn,
qmkcColumn,
qmkcjeColumn
});
grid = new GridPanel();
grid.setHeight(400);
grid.setWidth(975);
grid.setTitle("库存明细查询");
grid.setStore(store);
grid.setColumnModel(columnModel);
grid.setTrackMouseOver(false);
grid.setLoadMask(true);
grid.setSelectionModel(new RowSelectionModel());
grid.setFrame(true);
grid.setStripeRows(true);
grid.setIconCls("grid-icon");
/*final PagingToolbar pagingToolbar = new PagingToolbar(store);
pagingToolbar.setPageSize(14);
pagingToolbar.setDisplayInfo(true);
pagingToolbar.setDisplayMsg("当前显示的数据为: {0} - {1} of {2}");
pagingToolbar.setEmptyMsg("无显示数据");
NumberField pageSizeField = new NumberField();
pageSizeField.setWidth(40);
pageSizeField.setSelectOnFocus(true);
pageSizeField.addListener(new FieldListenerAdapter(){
public void onSpecialKey(Field field, EventObject e){
if (e.getKey() == EventObject.ENTER){
int pageSize = Integer.parseInt(field.getValueAsString());
pagingToolbar.setPageSize(pageSize);
}
}
});
ToolTip toolTip = new ToolTip("更改每页显示的数据,按回车生效");
toolTip.applyTo(pageSizeField);
pagingToolbar.addField(pageSizeField);
grid.setBottomToolbar(pagingToolbar);
grid.addListener(new PanelListenerAdapter(){
public void onRender(Component component){
store.load(0, 14);
}
});
*/
Toolbar topToolbar = new Toolbar();
topToolbar.addFill();
grid.setTopToolbar(topToolbar);
GridSearchPlugin gridSearch = new GridSearchPlugin(GridSearchPlugin.TOP);
gridSearch.init(grid);
gridSearch.setMode(GridSearchPlugin.LOCAL);
grid.addPlugin(gridSearch);
/*Toolbar bottomToolbar = new Toolbar();
bottomToolbar.addFill();
bottomToolbar.addButton(new ToolbarButton("条件清除",
new ButtonListenerAdapter() {
public void onClick(Button button, EventObject e) {
grid.clearSortState(true);
}
}));
grid.setBottomToolbar(bottomToolbar);*/
store.load();
final RecordDef recordDef1 = new RecordDef(new FieldDef[] {
new StringFieldDef("仓库名称"),
new StringFieldDef("库存数量"),
new StringFieldDef("库存金额"),
new StringFieldDef("当月消耗"),
new StringFieldDef("消耗金额") });
ColumnConfig clmcColumn1 = new ColumnConfig("仓库名称", "仓库名称", 320, false);
clmcColumn1.setAlign(TextAlign.CENTER);
ColumnConfig ggxhColumn1 = new ColumnConfig("库存数量", "库存数量", 110, false);
ggxhColumn1.setAlign(TextAlign.CENTER);
ColumnConfig jldwColumn1 = new ColumnConfig("库存金额", "库存金额", 200, false);
jldwColumn1.setAlign(TextAlign.CENTER);
ColumnConfig qmkcColumn1 = new ColumnConfig("当月消耗", "当月消耗", 110, false);
qmkcColumn1.setAlign(TextAlign.CENTER);
ColumnConfig qmkcjeColumn1 = new ColumnConfig("消耗金额", "消耗金额", 200, false);
qmkcjeColumn1.setAlign(TextAlign.CENTER);
ColumnModel columnModel1 = new ColumnModel(new ColumnConfig[]{
clmcColumn1,
ggxhColumn1,
jldwColumn1,
qmkcColumn1,
qmkcjeColumn1
});
String[][] data1 = null;
data1 = new String[1][5];
data1[0][0]= "";
data1[0][1]= "";
data1[0][2]= "";
data1[0][3]= "";
data1[0][4]= "";
MemoryProxy proxy1 = new MemoryProxy(data1);
ArrayReader reader1 = new ArrayReader(recordDef1);
Store store1 = new Store(proxy1, reader1,false);
store1.load();
grid.addGridRowListener(new GridRowListener(){
public void onRowDblClick(GridPanel grid, int rowIndex, EventObject e){
action.queryData1(new AsyncCallback(){
public void onFailure(Throwable caught) {
}
public void onSuccess(Object result) {
final RecordDef recordDef1 = new RecordDef(new FieldDef[] {
new StringFieldDef("仓库名称"),
new StringFieldDef("库存数量"),
new StringFieldDef("库存金额"),
new StringFieldDef("当月消耗"),
new StringFieldDef("消耗金额") });
ColumnConfig clmcColumn1 = new ColumnConfig("仓库名称", "仓库名称", 320, false);
clmcColumn1.setAlign(TextAlign.CENTER);
ColumnConfig ggxhColumn1 = new ColumnConfig("库存数量", "库存数量", 110, false);
ggxhColumn1.setAlign(TextAlign.CENTER);
ColumnConfig jldwColumn1 = new ColumnConfig("库存金额", "库存金额", 200, false);
jldwColumn1.setAlign(TextAlign.CENTER);
ColumnConfig qmkcColumn1 = new ColumnConfig("当月消耗", "当月消耗", 110, false);
qmkcColumn1.setAlign(TextAlign.CENTER);
ColumnConfig qmkcjeColumn1 = new ColumnConfig("消耗金额", "消耗金额", 200, false);
qmkcjeColumn1.setAlign(TextAlign.CENTER);
ColumnModel columnModel1 = new ColumnModel(new ColumnConfig[]{
clmcColumn1,
ggxhColumn1,
jldwColumn1,
qmkcColumn1,
qmkcjeColumn1
});
String[][] data1 = (String[][]) result;
MemoryProxy proxy1 = new MemoryProxy(data1);
ArrayReader reader1 = new ArrayReader(recordDef1);
Store store1 = new Store(proxy1, reader1,false);
grid1.reconfigure(store1, columnModel1);
store1.reload();
}
});
}
public void onRowClick(GridPanel grid, int rowIndex, EventObject e){
}
public void onRowContextMenu(GridPanel grid, int rowIndex, EventObject e){
}
});
panel.add(grid);
grid1 = new GridPanel();
grid1.setHeight(160);
grid1.setWidth(975);
grid1.setStore(store1);
grid1.setColumnModel(columnModel1);
grid1.setTrackMouseOver(false);
grid1.setLoadMask(true);
grid1.setSelectionModel(new RowSelectionModel());
grid1.setFrame(true);
grid1.setStripeRows(true);
panel.add(grid1);
RootPanel.get().add(panel);
}
});
}
}2008年6月29日 17:08
2个答案 按时间排序 按投票排序
-
实现grid1的rowdblclick事件处理,在事件处理方法中获取Grid1当前选择行的数据,然后组成查询条件,对grid2的store重新装载
grid.on('rowdblclick', function(grid, rowIndex, e) { var record = grid.getStore().getAt(rowIndex); if (record) { var params = {}; params['cond1'/*此处是grid2的store中附加到URL后参数名*/] = record.get('field1'/*此处是grid1中的列名*/); params['cond2'/*此处是grid2的store中附加到URL后参数名*/] = record.get('field2'/*此处是grid1中的列名*/); var store = grid2.getStore(); Ext.apply(store.baseParams, params); store.load(); } });
2008年6月29日 22:23
相关推荐
Gwt-Ext不仅提供了如表格(Grid)、分页、过滤、拖拽树、组合下拉框(Combobox)、目录、对话框、表单等高级组件,而且拥有丰富的API,确保了其功能的全面性和使用的灵活性。此外,Gwt-Ext遵循GNU Lesser General ...
这篇博客文章的标题“gwt-ext 实例”表明,作者分享了一个关于如何在GWT项目中使用gwt-ext库的实际示例。通过这个实例,读者可以学习到如何引入gwt-ext库,创建和配置UI组件,以及如何将这些组件整合到GWT应用中。 ...
《GWT-EXT2.0最佳实践教程》源代码打包下载资源主要涵盖了Google Web Toolkit (GWT) 和EXT-JS 2.0的结合使用,提供了丰富的实践案例和示例代码,旨在帮助开发者深入理解和应用这两项技术。GWT是一款强大的JavaScript...
【GWT-Ext 知识点详解】 GWT-Ext 是一个高级的网页开发控件库,它结合了 Google Web Toolkit (GWT) 和 ExtJs 的优势,为开发者提供了丰富的 UI 组件和强大的功能。GWT 是一个由 Google 开发的用于构建富互联网应用...
GWT-Ext 的核心特点在于它扩展了 GWT,融合了 ExtJS 的丰富界面组件,包括有排序功能的表格(Grid)、分页、过滤、拖拽功能的树、自定义的组合下拉框(Combobox)、目录、对话框、表单(Form)等。 1. **GWT-Ext 的...
- 扩展了GWT的功能,提供了高级UI组件如排序表格(Grid)、分页、过滤器、可拖拽的树形结构等。 - 支持高度自定义的组件如组合下拉框(Combobox)、目录、对话框、表单(Form)等。 - 提供了一个强大且易于使用的API...
GWText是一个基于Google Web Toolkit (GWT) 和EXT GWT (GXT) 框架的开源项目,用于构建富互联网应用程序(Rich Internet Applications, RIA)。这个“gwtext编写的小系统”是一个示例项目,旨在帮助初学者理解如何...
本书的编写初衷源于作者与ExtGWT开发者之间关于该框架细节的深入交流,意识到市场上急需一本全面介绍ExtGWT的书籍,以满足越来越多Java开发者对于进入Ajax和RIA领域的渴望。 #### 三、主要内容 1. **快速入门**:...
EXT-GWT的分页组件通常是与Grid或DataView结合使用的,提供了一种直观的方式来展示和操作大量的表格数据。 首先,实现EXT-GWT分页,你需要理解以下几个关键概念: 1. **Store**:存储数据的核心组件,它可以连接到...
### 关于《Developing with Ext GWT Enterprise RIA Development》的知识点 #### 一、概述与背景 本书《Developing with Ext GWT Enterprise RIA Development》由Grant K. Slender编写,出版时间为2009年5月。本书...
GXT(GWT-Ext)是一个基于Google Web Toolkit (GWT) 的JavaScript UI库,它扩展了GWT的功能,提供了丰富的用户界面组件和强大的数据网格处理能力。GXT的一个核心特性是支持CRUD(创建、读取、更新、删除)操作,这...
GXT,全称为Ext GWT (Google Web Toolkit),是一个基于Google Web Toolkit (GWT)的JavaScript库,专门用于构建富互联网应用程序(Rich Internet Applications,简称RIA)。它提供了大量的UI组件和高级功能,使得...
2. **组件使用**:详细讲解Ext GWT中的各种组件,如Panel、Window、Form、Grid等,以及如何通过布局管理器进行组件的组合与排列。 3. **数据绑定**:理解ModelData和Store的概念,学会使用Data Binding实现UI和后台...
总结来说,"Ext + GWT + Struts2.0"的开发模式允许你利用ExtJS的强大UI组件库,GWT的远程服务调用机制,以及Struts2.0的MVC架构,创建一个完整的、高性能的Web应用。这种组合提供了从用户交互、数据处理到服务器端...
《Developing with Ext GWT: Enterprise RIA Development》是一本专为Java开发者设计的深入指南,旨在帮助他们轻松进入Ajax和富互联网应用(RIA)领域。这本书由Grant K. Slender撰写,是基于Ext JS的激动人心的新UI...
**GXT (Ext GWT)** 是基于GWT的一个扩展库,提供了更多的UI组件和皮肤,尤其是桌面级应用风格的组件,如数据网格、图表和各种布局。GXT使得开发者能够构建更加美观且功能丰富的Web界面,同时保持GWT的开发效率和跨...
Ext GWT(GXT)是基于GWT的扩展框架,它进一步丰富了UI组件库,增强了稳定性和功能性,提供了更高级的企业级组件,如Grid、Menu、Tab、Chart等,使得开发者能够创建更加复杂且用户友好的界面。Ext GWT利用JavaScript...
1. **组件应用**:EXT的组件库被广泛使用,如EXT Grid用于数据展示,EXT Form用于用户输入,EXT Panel用于组织界面,EXT Toolbar用于添加操作按钮等。 2. **数据绑定**:GWT与EXT之间的数据交互通常通过GWT的Remote...
ExtJS Grid是一款强大的数据展示组件,常用于构建复杂的Web应用程序中的数据网格。多表头插件是ExtJS Grid的一个重要特性,它允许我们创建具有多层次、复杂结构的表头,以便更好地组织和呈现数据。在ExtJS Grid中,...