Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Description tooltips for Vaadin Grid header cells

Tags:

java

vaadin

I'd like to define descriptions for Grid header cells, similarly to how AbstractComponent.setDescription(String description) works (i.e. tooltip shown on mouse hover). As the Grid doesn't support this in itself, I tried adding a Label component into the header cell, and then use setDescription() on the label. I can get the info tooltip working like this, but the downside is that clicking on the label component doesn't trigger sorting. If I want to sort the column, I need to click the header cell on the really narrow area that's left between the right edge of the label component and the column border, where the sorting indicator will be shown. If you look at the screenshot below, the highlighted area is the label component, and in order to trigger sorting, the user needs to click on the space on the right side of the component.

Example Grid

Is there a better way to apply descriptions to header cells than the one I described? And if not, is there a way to make the sorting work properly when the header cell contains a Component?

like image 962
Markus Yrjölä Avatar asked Dec 06 '25 08:12

Markus Yrjölä


2 Answers

Based on the answer from kukis, I managed to come up with a simpler solution that doesn't require any JavaScript. Instead of adding a Label component into the header cell, I'm adding a div element manually with StaticCell.setHtml(), and setting the title attribute on it:

@Override
protected void init(VaadinRequest request) {
    Grid grid = new Grid();
    grid.addColumn("to");
    grid.addColumn("the");
    grid.addColumn("moon");

    Grid.HeaderRow headerRow = grid.getDefaultHeaderRow();
    headerRow.getCell("to").setHtml("<div title='Hello world'>to</div>");
    headerRow.getCell("the").setHtml("<div title='Hello world 2'>the</div>");
    headerRow.getCell("moon").setHtml("<div title='Hello world 3'>moon</div>");

    grid.addRow("1","2","3");
    grid.addRow("d","v","w");
    grid.addRow("g","s","h");

    setContent(new VerticalLayout(grid));
}
like image 68
Markus Yrjölä Avatar answered Dec 08 '25 21:12

Markus Yrjölä


Feature added to Vaadin 8.4.0

Feature added to Grid in Vaadin 8.4.0.

Ticket: https://github.com/vaadin/framework/pull/10489

Release notes: https://vaadin.com/download/release/8.4/8.4.0/release-notes.html

Grid headers and footers now support tooltips.

like image 29
Basil Bourque Avatar answered Dec 08 '25 20:12

Basil Bourque