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 see the attached screenshot, the highlighted area is the label component, and in order to trigger sorting, the user needs to click on the space left of the cell on the right side of the component.
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?
First of all, I agree with you that there ought to be a
com.vaadin.ui.Grid.Column.setDescription()
method so that it would be possible to have mouse-over tooltips for the column headers.
There’s one option I can think of: You can implement your own tooltip on right-click of the column header. You would add a Context Click Listener with the
grid.addContextClickListener method. In your listener you would then test if the header or the body of the grid was clicked. If header then which column? Once you got that you can launch a tooltip in a window. Takes some work, though.
Yes, I know that right-clicking isn’t the same as mouse-over but at least it will not screw up the standard grid column sorting feature.