You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components-twincolselect.asciidoc 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ---
  2. title: TwinColSelect
  3. order: 20
  4. layout: page
  5. ---
  6. [[components.twincolselect]]
  7. = TwinColSelect
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/multiple-value/list-builder"]
  11. endif::web[]
  12. The [classname]#TwinColSelect# field provides a multiple selection component
  13. that shows two lists side by side, with the left column containing unselected
  14. items and the right column the selected items. The user can select items from
  15. the list on the left and click on the ">" button to move them to the list on
  16. the right. Items can be deselected by selecting them in the right list and
  17. clicking on the "<" button.
  18. [[figure.components.twincolselect.basic]]
  19. .Twin Column Selection
  20. image::img/twincolselect-basic.png[width=50%, scaledwidth=80%]
  21. [classname]#TwinColSelect# is always in multi-select mode, so its selection
  22. is always a collection of the selected items in the right column.
  23. The selection columns can have their own captions, separate from the overall
  24. component caption, which is managed by the containing layout. You can set the
  25. column captions with [methodname]#setLeftColumnCaption()# and
  26. [methodname]#setRightColumnCaption()#.
  27. [source, java]
  28. ----
  29. TwinColSelect<String> select =
  30. new TwinColSelect<>("Select Targets");
  31. // Put some items in the select
  32. select.setItems("Mercury", "Venus", "Earth", "Mars",
  33. "Jupiter", "Saturn", "Uranus", "Neptune");
  34. // Few items, so we can set rows to match item count
  35. select.setRows(select.size());
  36. // Preselect a few items
  37. select.select("Venus", "Earth", "Mars");
  38. // Handle value changes
  39. select.addSelectionListener(event ->
  40. layout.addComponent(
  41. new Label("Selected: " + event.getNewSelection())));
  42. ----
  43. The resulting component is shown in <<figure.components.twincolselect.basic>>.
  44. The [methodname]#setRows()# method sets the height of the component by the
  45. number of visible items in the selection boxes. Setting the height with
  46. [methodname]#setHeight()# to a defined value overrides the rows setting.
  47. [WARNING]
  48. The [classname]#TwinColSelect# does not provide lazy loading mechanism.
  49. Hence it will slow down significantly if used with large itemsets.
  50. The lazy loading feature could be implemented using two single column Grids instead.
  51. Common selection component features are described in
  52. <<components-selection#components.selection,"Selection
  53. Components">>.
  54. == CSS Style Rules
  55. [source, css]
  56. ----
  57. .v-select-twincol {}
  58. .v-select-twincol-options-caption {}
  59. .v-select-twincol-selections-caption {}
  60. .v-select-twincol-options {}
  61. .v-select-twincol-buttons {}
  62. .v-button {}
  63. .v-button-wrap {}
  64. .v-button-caption {}
  65. .v-select-twincol-deco {}
  66. .v-select-twincol-selections {}
  67. ----
  68. The [classname]#TwinColSelect# component has an overall
  69. [literal]#++v-select-twincol++# style. If set, the left and right column
  70. captions have [literal]#++v-select-twincol-options-caption++# and
  71. [literal]#++v-select-twincol-options-caption++# style names, respectively. The
  72. left box, which displays the unselected items, has
  73. [literal]#++v-select-twincol-options-caption++# style and the right box, which
  74. displays the selected items, has
  75. [literal]#++v-select-twincol-options-selections++# style. Between them is the
  76. button area, which has overall [literal]#++v-select-twincol-buttons++# style;
  77. the actual buttons reuse the styles for the [classname]#Button# component.
  78. Between the buttons is a divider element with
  79. [literal]#++v-select-twincol-deco++# style.