Sorting does not work but selection get lost


I posted this in the wrong forum, sorry, so I repost it here :

I tried to make a grid with sortable columns, but it does not work directly, I have to sort the datasource (as in the documentation : (

Furthermore, when I use sortable columns on a grid with selection enabled, the selection get lost as soon as I click on the header, before the “sort” event, so it is even not possible to save the selection before sorting the datasource, in order to restore it at the end.

The selection should be kept when sorting, or for example, there could be some before/after events to save/restore the state manually.

Hello Sébastien

Unfortunately vaadin-grid cannot automatically sort its datasource. The component might be hooked to for example a remote source that it has no control over. As vaadin-grid queries the data (lazily) it’s only aware of the rows in its viewport at a given time. This is why returning a sub-set of correctly sorted source data is the responsibility of the developer.

The second question is kind of related. Selection in vaadin-grid is currently based on row indexes. As you sort the columns, vaadin-grid can’t know what’s the index of a certain row after the sorting is applied so it falls back to clearing the selection instead. You can always maintain a list of the selected items somewhere in store yourself (“select” event indicates a change in selection") and re-apply the selection with new row indexes after sorting.

Now that you mentioned it however, we should change the order of events on sort to make re-applying the selection easier.
Filed an issue of it at


I removed my previous reply as you described exactly what I meant ! :slight_smile:

Thanks a lot !!

Great, should be an easy fix. Thanks for reporting :slight_smile:


I am using grid table in my project as well as filter table .I have  some problem here that --> in filter table when we clicking on the table header ,first row will be automatically highlighting but coming to grid table ,it is not happening as filter table  and also when we click on grid cell it is selecting that cell only but in filter table when we click on any cell it will select entire row ,I want the same action in grid table 
 I want same behaviour as filter table in grid table how can I achieve it,is there is any possibility to do like that ,any code change or any method i can use .

     please give me any solution or any code change to fix  this bug . 
    And iam using the below code in my grid table in my project::

for (Map.Entry<String, Object[]> entry : defHdrRow.entrySet()) {
for (Map.Entry<String, Object[]> entry : prependHdrRow.entrySet()) {

Hi phani,

You’re using the Vaadin Framework Grid (Java version), whereas this topic was about the custom element (JavaScript Web Component).

It would be better if you posted a new topic for your issue, on the “Framework UI” category. Thanks!