简体   繁体   English

GWT-面板中的更新表

[英]GWT - update table in panel

I have a verticalPanel with a table in it. 我有一个带有桌子的verticalPanel。 OnModuleLoad I get data from database which I display in a table. OnModuleLoad我从数据库中获取数据,这些数据显示在表中。 On button click I want to add new data from a listbox to it. 在按钮上单击我要从列表框中向其添加新数据。 It works fine but I dont know how to update the table/panel. 它工作正常,但我不知道如何更新表/面板。 What I do at the momemt is to create a new Table to show the data but I cant delete the first table. 我在momemt所做的是创建一个新表来显示数据,但是我无法删除第一个表。 Do I have to attach the table to the panel to be able to delete it? 我必须将表格附加到面板上才能删除它吗? Actually I dont like this solution thats why I was wondering if theres an update method or something. 实际上,我不喜欢这种解决方案,这就是为什么我想知道是否有更新方法之类的原因。

Create Table 建立表格

public void createTimeTable(){
        //Table and Panel -> created globally
        //On Load -> get all times which are already booked
        serviceImplURL.getRpcDB().getBookedTimes(username, new AsyncCallback<ArrayList<Times>>() {
            /**
            */
            @Override
            public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub

            }
            /**
            */
            @Override
            public void onSuccess(ArrayList<Times> startList) {
                /**
                */

                    table.setRowCount(startList.size(), true);
                    table.setRowData(0, startList);


                    // Add column to show the start time.
                      TextColumn<Times> startColumn 
                      = new TextColumn<Times>() {
                         @Override
                         public String getValue(Times times) {
                            return Double.toString(times.getStart());
                         }
                      };
                      table.addColumn(startColumn, "Beginn");

                   // Add column to show the pause time.
                      TextColumn<Times> pauseColumn 
                      = new TextColumn<Times>() {
                         @Override
                         public String getValue(Times times) {
                            return Integer.toString(times.getPause());
                         }
                      };
                      table.addColumn(pauseColumn, "Pause in Minuten");

                   // Add column to show the end time.
                      TextColumn<Times> endColumn 
                      = new TextColumn<Times>() {
                         @Override
                         public String getValue(Times times) {
                            return Double.toString(times.getEnd());
                         }
                      };
                      table.addColumn(endColumn, "Ende");



                      //table panel
                      panel.setBorderWidth(1);      
                      panel.setWidth("400");
                      panel.add(table);
                      panel.getElement().setId("mainTable");


                      // Add the widgets to the root panel.
                      RootPanel.get().add(panel);

            }               
        });

First you have to correct your code. 首先,您必须更正您的代码。 you require to set data only. 您只需要设置数据。 right? 对? so no need to create table column again and again to change the data in it. 因此,无需一次又一次创建表来更改其中的数据。

First create table structure outside of rpc call method. 首先在rpc调用方法之外创建表结构。 then use the instance of table and set data in it. 然后使用表的实例并在其中设置数据。

you have to update datalist only, using methods like 您只需要使用类似的方法来更新数据列表

table.setRowCount(startList.size(), true);
table.setRowData(0, startList); 

Edit: 编辑:

   private void initilaize()
    {

                // Add column to show the start time.
                  TextColumn<Times> startColumn 
                  = new TextColumn<Times>() {
                     @Override
                     public String getValue(Times times) {
                        return Double.toString(times.getStart());
                     }
                  };
                  table.addColumn(startColumn, "Beginn");

               // Add column to show the pause time.
                  TextColumn<Times> pauseColumn 
                  = new TextColumn<Times>() {
                     @Override
                     public String getValue(Times times) {
                        return Integer.toString(times.getPause());
                     }
                  };
                  table.addColumn(pauseColumn, "Pause in Minuten");

               // Add column to show the end time.
                  TextColumn<Times> endColumn 
                  = new TextColumn<Times>() {
                     @Override
                     public String getValue(Times times) {
                        return Double.toString(times.getEnd());
                     }
                  };
                  table.addColumn(endColumn, "Ende");



                  //table panel
                  panel.setBorderWidth(1);      
                  panel.setWidth("400");
                  panel.add(table);
                  panel.getElement().setId("mainTable");


                  // Add the widgets to the root panel.
                  RootPanel.get().add(panel);
     }

    public void createTimeTable(){
            //Table and Panel -> created globally
            //On Load -> get all times which are already booked
            serviceImplURL.getRpcDB().getBookedTimes(username, 
new AsyncCallback<ArrayList<Times>>() {
                /**
                */
                @Override
                public void onFailure(Throwable caught) {
                    // TODO Auto-generated method stub

                }
                /**
                */
                @Override
                public void onSuccess(ArrayList<Times> startList) {
                    /**
                    */
                        table.setRowCount(startList.size(), true);
                        table.setRowData(0, startList);

                }               
            });

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

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