Grid and header click listener

Hi all,

We use the VAADIN table component to display a kind of dynamic report which reacts on columns reordering and cells clicks. But we decided to migrate to Grid instead of the table since the Grid performed is enhanced comparing to table one.

On of our big problems is that we can’t find an equivalent header table click listeners in the Grid component. We use this to display a kind of context menu containing actions related to the clicked column. We have searched for the same behavior in the Grid but can’t figure out a header click listener.

Why such listener is not implemented in the Grid ? Is it planned for further releases ? If not how can we implement the same functionality ?

Thanks for help

Hi,

a simple workaround would be to add a Layout component (and whatever else you’d like in the Layout) in the Header cell and use the click listener of that Layout.

Best regards,
Olli

Hi,

Thanks for your reply but how can we map between header property id of the column and the clicked layout in this case ?

Best regards

Hi,

You have the property information when you add the listener to the header cell, so you should be able to pass it to the listener as well.

Regards,
Olli

Hi,

Thanks for your help. I worked perfectly but next problem is that the grid supports columns reordering. And it seems that the column cannot be moved when the drag is situated on the component header cell. We noticed that the column is moved when the component put in the header cell is not occupying the hole header cell space.

Any Idea ?

Best regards

Hi,

I guess one option would be to use a Button instead of a Layout in the header cell; clicking on the button would trigger the click listener and clicking outside of the button could be used for drag to reorder.

-Olli

Hi,

If buttons supports right clicks i would try this and see the result. I hope I could use the grid context menu listener but the event don’t tell you what if a header cell is clicked.

Best regards.

With Vaadin 7.6, you should be able to add a ContextMenu to the buttons:
https://vaadin.com/blog/-/blogs/using-contextmenu-with-vaadin-7-6

Regards,
Olli

Hi all,

Finally we applied another solution to keep the column reordering behaviour like it is now. In fact we used the setHtml() instead of the setComponent() method in header cell. In the injected HTML we created a div tag that contains onclick and oncontextmenu events and we send back to the server all necessary information from the click event. We injected the column property ID in the id attribute of the division to use it later. So the injected HTML was :

${column_caption}

Then we injected java script function by calling :

JavaScript.getCurrent().addFunction(“calbackMethod”, new JavaScriptFunction() {// implementation here});

I hope it would help other having the same problem