gpt4 book ai didi

java - 如何正确添加数据到GXT Grid?

转载 作者:行者123 更新时间:2023-12-01 14:38:41 25 4
gpt4 key购买 nike

我有一个网络应用程序,我需要从文件中获取一些数据并填充到表中。这是包含此表的页面的代码:

public class Rules extends ContentPanel{
private final ServerManagementAsync serverManagementSvc = GWT.create(ServerManagement.class);
private ArrayList<PropertyItem> propslist;
private ArrayList<PropertyItem> itemArrayList;
private EditorGrid<PropertyItem> grid;

public Rules(final String customerId){
setLayout(new FlowLayout(10));

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Name");
column.setWidth(220);

TextField<String> text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);

column = new ColumnConfig();
column.setId("type");
column.setHeader("Type");
column.setWidth(220);

TextField<String> typeText = new TextField<String>();
typeText.setAllowBlank(false);
column.setEditor(new CellEditor(typeText));
configs.add(column);

column = new ColumnConfig();
column.setId("value");
column.setHeader("Value");
column.setWidth(220);
configs.add(column);

final ListStore<PropertyItem> store = new ListStore<PropertyItem>();
propslist = getPropslist(customerId);

for (PropertyItem propertyItem: propslist){
store.insert(propertyItem, 0);
}

ColumnModel cm = new ColumnModel(configs);

setHeading("Settings");
setFrame(true);
setWidth(600);
setLayout(new FitLayout());

grid = new EditorGrid<PropertyItem>(store, cm);
grid.setAutoExpandColumn("name");
grid.setBorders(true);
add(grid);

ToolBar toolBar = new ToolBar();
setTopComponent(toolBar);
setButtonAlign(Style.HorizontalAlignment.RIGHT);

addButton(new Button("Refresh", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
store.insert(getPropslist(customerId), 5);
}
}));
addButton(new Button("Add", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
store.commitChanges();
}
}));


}

public ArrayList<PropertyItem> getPropslist(String customerId){
itemArrayList = new ArrayList<PropertyItem>();
AsyncCallback<ArrayList<PropertyItem>> callback = new AsyncCallback<ArrayList<PropertyItem>>() {
@Override
public void onFailure(Throwable throwable) {

}

@Override
public void onSuccess(ArrayList<PropertyItem> propertyItems) {
itemArrayList = propertyItems;
Window.alert("read successful");
}
}
};
serverManagementSvc.getProperties(customerId, callback);
return itemArrayList;
}
}

当我运行我的应用程序时,我只看到列名称,而单元格中没有数据(当然也没有单元格)。作为示例,我使用了这个:Ext GWT 2.2.6 Explorer(Grid)

我不明白什么会导致这样的问题。这可能是什么原因?

最佳答案

因为您的 propsList 正在异步填充,所以网格会在服务器调用返回之前呈现。

要解决此问题,首先使商店成为像网格一样的私有(private)属性(property)

接下来,移动填充您商店的代码:

    for (PropertyItem propertyItem: propslist){
store.insert(propertyItem, 0);
}

进入onSuccess您的回调方法。

最后,您可能还需要调用: grid.reconfigure(grid.getStore(), grid.getColumnModel());只是为了让网格再次渲染。

关于java - 如何正确添加数据到GXT Grid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16215028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com