StackOverFlow
StackOverFlow

Reputation: 4614

GWT CELLTABLE column's cell value updation

I am using gwt2.3

My celltable contains 10 rows, 5 columns.

All cells in 1st row is empty,editable.

Whenever user clicks on column cell lets say 1st row X 3rd column then user will edit that cell say "xyz". after that when user click on button: "update column cell" then xyz value set to all cell present in that column.

I am using different celltype in celltable.

How to set/update all cell value in that particular column/page whose 1st cell is edited

Any help or guidance in this matter would be appreciated

Upvotes: 0

Views: 6473

Answers (1)

Ümit
Ümit

Reputation: 17499

Create a FieldUpdater in order to push back the changes to your Domain object. Then in the onClick callback of your button update your List with the values from the first row.

For example for an arbitrary TextInputColumn which takes a MyDTO class (can be any domain object) as the value type you can define following FieldUpdater:

myColumn.setFieldUpdater(new FieldUpdater() {

    @Override
    public void update(int index, MyDTO object, String value) {
        // Push the changes into the MyDTO. At this point, you could send an
        // asynchronous request to the server to update the database.
        object.someField = value;

        // Redraw the table with the new data.
        table.redraw();
    }
});

You have to set such a FieldUpdater for all 5 columns. (someField is the field in your DTO which you want to update).

Now in the onClick() callback of the button you have to update the actual list. Looks something like that:

update_column_cell.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
         //Supose listDataProvider is the instance of your DataSource for your CellTable
         List<MyDTO> list = listDataProvider.getList();
         // get cell values for the first row (this is for one cell)
         newSomeField = list.get(0).someField;
         newSomeField2 = list.get(0).someField2;
         for (int i = 1;i<list.size();i++) {
              MyDTO dto = list.get(i);
              if (newSomeField != null && newSomeField.isNotEmpty()) {
                    dto.someField = newSomeField;
              }
              if (newSomeField2 != null && newSomeField2.isNotEmpty()) {
                    dto.someField2  = newSomeField2;
              }
         }
    }
})

This example only handles two fields of your DTO. You will probably have to extend it to cover all 5 fields you are showing as columns in your CellTable

Upvotes: 5

Related Questions