gwtcelltable

How do I prevent a CellTable RowElement from being redrawn after a SelectionChangehander fires?


I'm probably doing something else wrong but I've followed examples given here:

How to remove a row from the Cell Table and GWT get CellTable contents for printing or export

to accomplish my goal and the result is close but not quite right.

I have a page with two widgets. The first wiget contains a CellTable that uses an aSync ListDataProvider to pull results and populate a table. The table has a selection change event handler associated with it that loads further details about the selected item into the second widget below it.

public OrderAdminTable() {
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
    @Override
    public void onSelectionChange(SelectionChangeEvent event) {
      OrderAdminListProxy selected = selectionModel.getSelectedObject();
          if (selected != null && orderSnapShot != null) {
                orderSnapShot.loadSnapShot(selected);
          }
       }
    });

    initTable();
    this.addStyleName("order-list fixed_headers BOM");
    this.setSelectionModel(selectionModel);
}

Once the second widget has loaded the details about the selected item, the user can remove the item from the table/list by clicking a button in the RootPanel that is the parent of both widgets.

searchView.getCmdReview().addClickHandler(new ClickHandler() {
        @Override public void onClick(ClickEvent event) {
            searchView.getOrderAdminSnapshot().reviewOrder();//this line calls a web service that deletes the item from the server data
            dataProvider.getList().remove(searchView.getOrderAdminSnapshot().getSelectedOrder());
            for(int i=0;i<table.getRowCount();i++){
                TableRowElement row = table.getRowElement(i);
                for(int j=0;j<row.getCells().getLength();j++){
                    if(row.getCells().getItem(j).getInnerText().contains(searchView.getOrderAdminSnapshot().getSelectedOrder().getSalesOrderNumber())){
                        row.setAttribute("removed", "true");
                        row.addClassName("hidden");
                    }
                }
            }
        }
    });

This all works fine until you select another item in the table. When that happens, the selection change event seems to redraw the table and remove my custom attribute and class from the previously selected item. This makes it appear in the list again.

The ultimate goal here is to avoid a round trip to the server to pull new results when you remove an item from the list. The line "searchView.getOrderAdminSnapshot().reviewOrder();" makes a web service call that removes the item from the data on the server side so it does not appear in subsequent reloads.

Is there some way to force the selection change event to maintain the state of the table row that was previously selected? Is there a better way to remove the selected item from the list? Any advice would be appreciated.


Solution

  • Once you remove the object from the list dataProvider.getList().remove, it should disappear from the table. There is no need to hide the row - this row should be gone. So your loop should never find it.