0

In Vaadin 8 framework, using Vaadin Grid, how do I present a Boolean object in each row as a checkbox?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Dan
  • 23
  • 1
  • 2

3 Answers3

3

Display a Unicode character

An alternative to the other correct Answer is: plain text. Display one of the Unicode characters representing checkboxes on either state, checked or unchecked.

Write code that chooses one or the other for the Boolean value. Write the code as a column renderer, specifically a TextRenderer.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
1

I think the easiest solution is to use the ComponentRenderer introduced with Vaadin 8.1 (currently beta, so you need to get it from snapshot repository). See Vaadin docs: https://vaadin.com/docs/-/part/framework/components/components-grid.html#components.grid.renderer.

Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71
  • 1
    You are welcome. If it helped, you can mark it as answer. For future questions please read https://stackoverflow.com/help/how-to-ask first if you don't want to get down-votes of your question. – Steffen Harbich Jun 19 '17 at 11:30
  • components are quite heavy. you can use a simple HtmlRenderer instead. – d2k2 Jun 23 '20 at 19:21
1

Example with VaadinIcons

enter image description here

grid.addColumn(user -> user.isFreeUser() ? VaadinIcons.CHECK.getHtml() : null)
        .setRenderer(new HtmlRenderer())
        .setCaption("Free User");
d2k2
  • 726
  • 8
  • 16