如何在GWT中更新后刷新网格?

问题描述 投票:1回答:2

我正在开发一个应用程序,我有编辑按钮用于编辑帐户。当我编辑帐户时,应该使用新信息更新网格。但是,在我继续进行其他观点后,我就会回来。但是我想在用户点击编辑表单中的提交按钮后立即看到更新的信息。所以,我找不到刷新网格的方法。我用google搜索它但没有任何帮助(如grid.getView.refresh等)。这是我的类,在getToolbar方法中,逻辑应该在用户单击提交按钮时完成:

  @Override
    protected void onRender(Element parent, int index) {
        super.onRender(parent, index);
        setLayout(new FitLayout());
        setBorders(false);
        initTable();

    }

    protected void initTable() {
        getToolBar();
        initGrid(); 

        tableContainer = new ContentPanel();
        tableContainer.setBorders(false);
        tableContainer.setBodyBorder(false);
        tableContainer.setHeaderVisible(false);
        tableContainer.setTopComponent(accountsToolBar);
        tableContainer.setScrollMode(Scroll.AUTO);       
        tableContainer.setLayout(new FitLayout());
        tableContainer.add(grid);
        add(tableContainer);

    }

    private void initGrid() {
        RpcProxy<ListLoadResult<GwtGroupedNVPair>> proxy = new RpcProxy<ListLoadResult<GwtGroupedNVPair>>() {

            @Override
            protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtGroupedNVPair>> callback) {
                gwtAccountService.getAccountInfo(selectedAccount.getId(), callback);
            }
        };

        loader = new BaseListLoader<ListLoadResult<GwtGroupedNVPair>>(proxy);
        loader.addLoadListener(new DataLoadListener());

        store = new GroupingStore<GwtGroupedNVPair>(loader);
        store.groupBy("groupLoc");

        ColumnConfig name = new ColumnConfig("nameLoc", MSGS.devicePropName(), 50);
        ColumnConfig value = new ColumnConfig("value", MSGS.devicePropValue(), 50);

        List<ColumnConfig> config = new ArrayList<ColumnConfig>();
        config.add(name);
        config.add(value);

        ColumnModel cm = new ColumnModel(config);
        GroupingView view = new GroupingView();
        view.setShowGroupedColumn(false);
        view.setForceFit(true);
        view.setEmptyText(MSGS.accountNoSelectedAccount());

        grid = new Grid<GwtGroupedNVPair>(store, cm);
        grid.setView(view);
        grid.setBorders(false);
        grid.setLoadMask(true);
        grid.setStripeRows(true);
        grid.setTrackMouseOver(false);
        grid.disableTextSelection(false);
        updateAccountInfo();
        add(grid);
    }

    protected void updateAccountInfo() {
        if (store != null) {
            store.removeAll();
            loader.load();
        }
    }

    private ToolBar getsToolBar() {

       accountsToolBar = new ToolBar();
      accountsToolBar.setHeight("27px");
      if (currentSession.hasAccountUpdatePermission()) {
          //
          // Edit Account Button
          editButton = new EditButton(new SelectionListener<ButtonEvent>() {

              @Override
              public void componentSelected(ButtonEvent ce) {
                  if (selectedAccount != null) {
                      final AccountForm accountForm = new AccountForm(currentSession, selectedAccount);
                      accountForm.addListener(Events.Hide, new Listener<ComponentEvent>() {

                          public void handleEvent(ComponentEvent be) {


                              setAccount(accountForm.getExistingAccount());
                              refresh();

                          }
                      });
                      accountForm.show();
                  }
              }
          });
          editButton.setEnabled(true);

          accountsToolBar.add(editButton);
          accountsToolBar.add(new SeparatorToolItem());
      }
      return accountsToolBar;
  }

    public void refresh() {
      if (initialized && dirty && selectedAccount != null) {
          updateAccountInfo();
          dirty = false;
      }
      if (selectedAccount != null) {
          if (formPanel != null) {
              formPanel.show();
          }
          editButton.setEnabled(true);
      } else {
          if (formPanel != null) {
              formPanel.hide();
          }
          editButton.setEnabled(false);
      }

  }

当用户点击提交时,有人知道如何刷新我的网格吗?

java gridview gwt gxt
2个回答
0
投票

您需要将更改提交到模型:

store.commitChanges();

0
投票

如果您知道您的商店已更改,请尝试:

grid.getView().refresh(true);
© www.soinside.com 2019 - 2024. All rights reserved.