Search code examples
gwtdatabase-connectionuibinderflextable

How to populate the flex table in GWT from the backend


I have to pull out values from backend and fill it as rows in the flex table. I am not using static data, so I cannot use:

table.setText(0, 0, "Name");
table.setText(0, 1,"Birthdate");
table.setText(0, 2, "Address");

How can I pull out data and fill it as rows in flex table. Or should I use a Grid table for the same?


Solution

  • What's about something like this. In another class you could load your data from backend and create new Car Objekts and pass them to the MyCarFlexTable class.

    class MyCarFlexTable extends FlexTable {
    
     private int rowNumber;
     private List<Car> cars;
    
     public MyCarFlexTable(List<Car> cars) {
      this.cars = cars;
      initTable();
     }
    
     private void initTable() {
      for(Car c : cars) {
       // define which data is printed in which column
       setText(rowNumber, 0, c.getId()); // Id of Car
       setWidget(rowNumber, 1, new Label(c.getName())); // Name of Car
       // add more Columns
       rowNumber++;
      }
     }
    }