How to find out if the text in a grid cell is truncated ?

Using Vaadin 7 , I am trying to display “tooltip” (only) if the text in a grid cell is truncated (with ellipsis “…”).

How can I find out if the text in the cell is truncated ?

I tried to find out the width of the column( to compare it to the length of the string in a cell). But the width of the column always returns “-1.0”.

Thank you

The width is -1.0 if it is undefined, i.e. Grid is autoadjusting the width according to content.

There is no method to detect the presence of ellipsis from server side java. In general detecting ellipsis is far from trivial. In theory it could be possible to write Grid client side extension or custom renderer with some logic to detect it as described in this StackOverflow discussion


https://stackoverflow.com/questions/7738117/html-text-overflow-ellipsis-detection

There will be some performance overhead if this is used extensively.

Staying on the the server side :

Is it possible to get the current (ACTUAL) widtth of the cell/column ?
For example if the user resizes a colum in the grid, I want to know, what is the actual resized width.

Thanks

No, the server doesn’t know width of the resized columns, that is not communicated from the client. You will need to fetch it from the client side some way - either with a custom Extension and an RPC call or a JavaScript callback.

-Olli

You can use a Table and this: https://vaadin.com/directory/component/tabletooltips
Displays tooltips only for truncated cells (but no ellipsis)

I added the method getColumnWidth(…) in GridScrollExtension add-on, to make it easier to get the actual widths of the columns.


https://vaadin.com/directory/component/gridscrollextension-add-on