Skip to content

Instantly share code, notes, and snippets.

@ripla
Created November 19, 2015 14:07
Show Gist options
  • Save ripla/f407ced5a467fa74ec17 to your computer and use it in GitHub Desktop.
Save ripla/f407ced5a467fa74ec17 to your computer and use it in GitHub Desktop.
Quick test to demonstrate sorting one column based on another, hidden column
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
IndexedContainer mainContainer = new IndexedContainer();
mainContainer.addContainerProperty("prop1", Integer.class, "");
mainContainer.addContainerProperty("prop2", Integer.class, "");
mainContainer.addContainerProperty("prop3", Integer.class, "");
Item item = mainContainer.addItem(1);
item.getItemProperty("prop1").setValue(1);
item.getItemProperty("prop2").setValue(4);
item.getItemProperty("prop3").setValue(3);
item = mainContainer.addItem(2);
item.getItemProperty("prop1").setValue(3);
item.getItemProperty("prop2").setValue(5);
item.getItemProperty("prop3").setValue(2);
mainContainer.setItemSorter(new DefaultItemSorter() {
@Override
protected int compareProperty(Object propertyId,
boolean sortDirection, Item item1, Item item2) {
if ("prop3".equals(propertyId)) {
return super.compareProperty("prop2", sortDirection, item1,
item2);
} else {
return super.compareProperty(propertyId, sortDirection,
item1, item2);
}
}
});
Table table = new Table("", mainContainer);
table.setVisibleColumns("prop1", "prop3");
layout.addComponent(table);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment