Trace:
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Last revision Both sides next revision | ||
vaadin:code_snippets [2018/02/12 06:59] admin [Checkbox in Table Header] |
vaadin:code_snippets [2018/02/12 22:29] admin |
||
---|---|---|---|
Line 29: | Line 29: | ||
System.out.println("Pressed!"); | System.out.println("Pressed!"); | ||
} | } | ||
+ | }); | ||
+ | </file> | ||
+ | |||
+ | ==== Checkbox in Grid Header ==== | ||
+ | |||
+ | If you want to show a checkbox in the header of a Grid: | ||
+ | |||
+ | {{:vaadin:grid_checkbox.png?nolink|}} | ||
+ | |||
+ | use following code: | ||
+ | |||
+ | <file java> | ||
+ | CheckBox cbx = new CheckBox(); | ||
+ | cbx.addValueChangeListener(new ValueChangeListener<Boolean>() | ||
+ | { | ||
+ | @Override | ||
+ | public void valueChange(ValueChangeEvent<Boolean> event) | ||
+ | { | ||
+ | System.out.println("Pressed!"); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | UIFactoryManager.getFactory().invokeLater(() -> | ||
+ | { | ||
+ | // Cast the resource to a Grid. | ||
+ | ((Grid)((VaadinGrid)navLoggings.getUIResource()).getResource()) | ||
+ | // Get the first (automatically added) row. | ||
+ | .getHeaderRow(0) | ||
+ | // Get the cell for the column we want. | ||
+ | .getCell("CHECK") | ||
+ | // Add the component. | ||
+ | .setComponent(cbx); | ||
}); | }); | ||
</file> | </file> |