Sunday, October 27, 2013

Strange issue with GWT sorting columns of a cell table

Hi everyone,

I'm currently trying to implement column sorting in a cell table for my data, however my data doesn't sort and the sort arrow only moves when I click on a row after clicking on a column header. Not sure what I did wrong since most of what I have follows closely to the GWT tutorials and the GWT show case example.

If anyone could give me some pointers that would be great :) 

I'm thinking either I'm not properly triggering the sorting or the cell table content isn't loading.

public class BrowseVendorsContent extends Content {
private static final String pageName = "Browse Vendors";
private static final String pageStub = "vendors";

private final BrowseVendorsServiceAsync browseVendorsService = GWT
.create(BrowseVendorsService.class);

public BrowseVendorsContent(Sneaky_Xpress module) {
super(module);
}

@Override
public String getPageName() {
return pageName;
}

@Override
public String getPageStub() {
return pageStub;
}

@Override
public void getAndChangeContent(final String input) {
browseVendorsService.browseVendorsServer(input,
new AsyncCallback>() {
public void onFailure(Throwable caught) {
module.addMessage(GENERIC_ERROR_MESSAGE);
}

            public void onSuccess(List<Vendor> result) {                  HTMLPanel content = new HTMLPanel(""); // The new                                                          // content to                                                          // return                    // The sub-navigation bar                  HTMLPanel list = new HTMLPanel("ul", "");                  list.addStyleName("nav nav-tabs");                    // The tabs in the sub-navigation bar                  HTMLPanel listView = new HTMLPanel("li", "");                  HTMLPanel mapView = new HTMLPanel("li", "");                    // Links for the tabs                  Anchor listViewLink = new Anchor("List View");                  listViewLink.addClickHandler(new PageClickHandler(                          BrowseVendorsContent.this, "list"));                  listView.add(listViewLink);                    Anchor mapViewLink = new Anchor("Map View");                  mapViewLink.addClickHandler(new PageClickHandler(                          BrowseVendorsContent.this, "map"));                  mapView.add(mapViewLink);                    // Create the sub-navigation bar                  list.add(listView);                  list.add(mapView);                  content.add(list);                    // Load the appropriate view                  if (input.equals("map")) {                      mapView.addStyleName("active");                      listView.removeStyleName("active");                      // Add the map etc.                  } else {                      // By default load the list view                      listView.addStyleName("active");                      mapView.removeStyleName("active");                        // Add data table under List view                      Widget table = displayDataInTable(result);                      content.add(table);                  }                    module.changeContent(content);              }          });  

}

public Widget displayDataInTable(List vendorList) {
// Create new cell table object
CellTable table = new CellTable();

// Configure table to display all results onto one page  table.setPageSize(vendorList.size());    // Configure to select a row vs one cell at a time  MultiSelectionModel<Vendor> selectionModel = new MultiSelectionModel<Vendor>();  table.setSelectionModel(selectionModel);    // Create a list data provider.  final ListDataProvider<Vendor> dataProvider = new ListDataProvider<Vendor>();    // Instantiate sort handler  ListHandler<Vendor> colSortHandler = new ListHandler<Vendor>(          vendorList);    // Add Key column and sort to column  TextColumn<Vendor> keyCol = new TextColumn<Vendor>() {      @Override      public String getValue(Vendor vendor) {          return vendor.getVendorId();      }  };  table.addColumn(keyCol, "Key");  keyCol.setSortable(true);  colSortHandler.setComparator(keyCol, new KeyComparator());    // Add Name column and sort to column  TextColumn<Vendor> nameCol = new TextColumn<Vendor>() {      @Override      public String getValue(Vendor vendor) {          return vendor.getName();      }  };  table.addColumn(nameCol, "Name");  nameCol.setSortable(true);  colSortHandler.setComparator(nameCol, new NameComparator());    // Add Location column  TextColumn<Vendor> locCol = new TextColumn<Vendor>() {      @Override      public String getValue(Vendor vendor) {          return vendor.getLocation();      }  };  table.addColumn(locCol, "Location");  locCol.setSortable(true);  colSortHandler.setComparator(locCol, new LocComparator());    // Add Description column  TextColumn<Vendor> desCol = new TextColumn<Vendor>() {      @Override      public String getValue(Vendor vendor) {          return vendor.getDescription();      }  };  table.addColumn(desCol, "Description");  desCol.setSortable(true);  colSortHandler.setComparator(desCol, new DesComparator());    // Add the cellList to the dataProvider.  dataProvider.addDataDisplay(table);    // Add col sort handler to table  table.addColumnSortHandler(colSortHandler);  table.getColumnSortList().push(keyCol);    // Set to query result  dataProvider.setList(vendorList);    // return table and display on page  return table;  

}
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment