문제

I have a verticalPanel with a table in it. OnModuleLoad I get data from database which I display in a table. 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. 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. 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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top