Search code examples
rowvaadin7

How to hide vaadin Table row with an empty cell?


I am using a vaadin Table to put some rows with two columns, so each row has a vaadin Tree (I am not using a TreeTable) in the first cell and a description (string) in the second cell. So when I click on a Tree item, it edits the description cell of the row.

Then I have added a filter on each Tree to filter on the nodes's caption. So if a Tree doesn't have any captions passing the filter, the Tree isn't display.

But in this way, the table contains some row with nothing in the first cell and a description in the second and that is not ergonomic at all so what I want now is find a way to filter the Table row and hide the ones which are empty in the first cell.

I hope my question understandable.


Solution

  • I resolved my problem using the size() method of the Tree class. Indeed, this method returns the number of visible nodes in the Tree. So if Tree has a filter and none of its nodes are displayed, then size() will return 0.

    So all I had to do is updating my table style with myTable.setCellStyleGenerator() and in the getStyle() method, I get the Tree of my row and I get its size, if the size is 0, I hide the table row with css.

    I think it could be a better way to hide these rows with a table filter but I'm still working on it.

    thanks,

    Tom