简体   繁体   English

如何将行添加到GXT网格

[英]How to add rows to a GXT grid

I'm trying to create a fairly simply GWT app using the GXT framework, and am doing this based on the eBook "Ext GWT 2.0 Beginners Guide". 我正在尝试使用GXT框架创建一个相当简单的GWT应用,并根据电子书“ Ext GWT 2.0初学者指南”进行此操作。 It details all the step for building an app using GXTs MVC model, and most of it is working as expected, however I can not - for the life of it - add new rows to my Grid. 它详细介绍了使用GXTs MVC模型构建应用程序的所有步骤,并且大多数功能都按预期运行,但是-在它的生命周期内,我无法向Grid添加新行。

The initial loading of the Grid data (through itemStore, loader, and an RPCProxy work correct). 网格数据的初始加载(通过itemStore,加载程序和RPCProxy工作正常)。

However every time I fire the event that triggers adding a new row, the ListStore to which I want to add, is empty (not null! but empty) - even though my Grid is showing data after the initial load! 但是,每当我触发触发添加新行的事件时,我要添加到的ListStore都是空的(不是null!而是空的)-即使我的Grid在初始加载后显示数据!

Here is some of the relevant code: 以下是一些相关代码:

public class MessageGrid extends LayoutContainer {
    private final Grid<ModelData> grid;
    private final ListLoader<ListLoadResult<MarketingMessage>> loader;
    private final ListStore<ModelData> itemStore;
    public MessageGrid() {
        setLayout(new FitLayout());
        final MarketingServiceAsync marketingService = Registry.get(MarketingUIConstants.MARKETING_SERVICE);
        RpcProxy<List<MarketingMessage>> proxy = new RpcProxy<List<MarketingMessage>>() {
            @Override
            protected void load(Object loadConfig, final AsyncCallback<List<MarketingMessage>> callback) {
                marketingService.getMessages(callback);
            }
        };
        final List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
        columns.add(new ColumnConfig("col1", "Name", 100));
        columns.add(new ColumnConfig("col2", "Phone", 100));
        final ColumnModel columnModel = new ColumnModel(columns);       
        loader = new BaseListLoader<ListLoadResult<MarketingMessage>>(proxy);
        itemStore = new ListStore<ModelData>(loader);
        grid = new Grid<ModelData>(itemStore, columnModel);
        grid.setBorders(true);
        grid.setAutoExpandColumn("sentTime");
        grid.setAutoHeight(false);
        grid.setHeight("100%");     
    }

    @Override
    protected void onRender(Element parent, int index) {
        super.onRender(parent, index);
        loader.load();
        add(grid);
    }

    public void addMessage(MarketingMessage marketingMessage) {
        itemStore.add(new MarketingMessage("test", "test")));
    }
}

addMessage() is being called by the owning component (a View to which this LayoutContainer has been added). 所属组件(已添加此LayoutContainer的View)正在调用addMessage()。

If I set a breakpoint inside the addMessage() method, my itemStore has size 0 (same goes for grid.getStore() for that matter). 如果我在addMessage()方法中设置一个断点,则我的itemStore的大小为0(对于grid.getStore()也是一样)。

I've tried various different changes to this code and I have yet to see a row being added. 我已经尝试过对该代码进行各种不同的更改,但尚未看到添加行。

On a similar note: if inside the addMessage() method I try to do a reload from the proxy - since I do update the server side data as well - ie. 在类似的注释上:如果在addMessage()方法内部,则尝试从代理进行重新加载-因为我也确实更新了服务器端数据-即。 loader.load(), it also does not have any visible effect. loader.load(),它没有任何可见的效果。

The loader is going to be asynchronous - it needs to wait for the server (MarketingService) to return values. 加载程序将是异步的-需要等待服务器(MarketingService)返回值。 Are you certain that this is returning a non-empty list? 您确定这将返回非空列表吗? Verify this by replacing the callback in your proxy with your own callback that checks the contents returned to the client (it may not even be called at all if the server threw an exception). 通过用您自己的回调检查代理中的回调来验证这一点,该回调检查检查返回给客户端的内容(如果服务器引发异常,甚至可能根本不会调用它)。

If addMessage is called onRender or shortly thereafter, it may be too early, and the server may not have returned data yet, so the store may still be empty. 如果addMessage在onRender或此后不久被调用,则可能为时过早,并且服务器可能尚未返回数据,因此存储可能仍为空。 If called from a button click or something, this won't be an issue. 如果通过按钮单击或其他方式调用,则不会有问题。

Check your log for exceptions, you are passing a Proxy that handles a List of items to a Loader that expects a ListLoadResult - this could also be a source of errors. 检查日志中是否有异常,您正在将处理项列表的代理传递给需要ListLoadResult的加载器-这也可能是错误的来源。 The confusing generics in GXT 2 should mostly be resolved in 3, which is currently in beta. GXT 2中令人困惑的泛型通常应该在3(目前处于测试版)中解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM