Skip to content

Instantly share code, notes, and snippets.

@KrishnaKotari
Created April 2, 2015 06:06
Show Gist options
  • Save KrishnaKotari/4d043616df2b3378f4f1 to your computer and use it in GitHub Desktop.
Save KrishnaKotari/4d043616df2b3378f4f1 to your computer and use it in GitHub Desktop.
All Code related to Part 1 of my series on Vaadin Grid
//This doesn't give you caption
Grid grid = new Grid();
// This creates a caption and can be seen on the top left corner of the grid
Grid grid = new Grid("Basic");
//Add few columns followed by Data
grid.addColumn("name", String.class);
grid.addColumn("city", String.class);
grid.addColumn("pincode", String.class)
....
// Add some data rows
grid.addRow("Krishna", "Bangalore","560085");
grid.addRow("Anirudh", "Sindhanur","584128");
grid.addRow("Harin", "Bangalore","560027");
grid.addRow("Anil", "Vijayawada","520007");
/Initialize the container
BeanItemContainer<Person> container = new BeanItemContainer<Person>(Person.class);
container.add(new Person(1, "Krishna","Bangalore","560085");
container.add(new Person(2, "Anirudh", "Sindhanur","584128");
container.add(new Person(3, "Harin", "Bangalore","560027");
container.add(new Person(4, "Anil", "Vijayawada","520007");
//Add the container to the datasource
grid.setContainerDataSource(container);
grid.addSelectionListener(new SelectionListener() {
@Override
public void select(SelectionEvent event) {
Set<Object> itemIDs = event.getSelected();
//TODO do something with the items
}
});
// From the above example, I wish to hide the PersonID, so I do the following
grid.removeColumn("personID");
// From the above Person example
grid.setColumnOrder("personName", "city", "pincode");
// Again from the Person example
// Get the Column object associated with the property
Column city = grid.getColumn("city");
// Set the Column Caption
city.setHeaderCaption("Person City");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment