0

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);

            }               
        });
kArvee
  • 84
  • 1
  • 11

1 Answers1

1

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);

                }               
            });
bNd
  • 7,512
  • 7
  • 39
  • 72
  • this create table method is only used once to get the times ... then I have an update method which is called when I click a button. At the moment Im calling the createTimeTable method in the update method. But usually I only want to update the table not to create it again. – kArvee Mar 20 '13 at 08:44
  • update table like receiving data from database like before because it is possible that data is deleted or added but not edited. When I click the button I want to display the data I inserted into DB in the table. – kArvee Mar 20 '13 at 08:50
  • plz see I Edit my answer. do something like this. initialize column & and table once call this method one time only. – bNd Mar 20 '13 at 08:56
  • hm I cant see a difference to mine then. If I call them once theyre created on start. But how do I refresh the table on button click without refreshing the page? – kArvee Mar 20 '13 at 09:07
  • 1
    @kArvee Did you try takrbuiam's solution? I think the first question is: why are you creating the columns every time you receive a response from the server? Try moving your column creation to your method that creates the table, and execute that method only once (not every time you request data). If you **are** going to create the columns after every response from the server, you could try doing the `table.setRowData()` after creating the columns. – Andy King Mar 20 '13 at 15:29
  • but as I already said, I only request the data once. There is no difference if I write the creation of the columns outside the request. I have "createTimeTable" which is executed only once and then I have an update method where I want to get all data from database and update my table I have. Just writing table.setRowData() and table.setRowCount() - as takrbuiam mentioned - doesnt do anything. – kArvee Mar 21 '13 at 06:56
  • ok I found out why it was not working properly. Im calling the update method from another class, hence my table data is null. So now Im about to get my "mainTable" and update it. It should work then. Thanks for your help! – kArvee Mar 21 '13 at 10:28