Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Sorting does not work but selection get lost
Hi,
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 : (https://cdn.vaadin.com/vaadin-components/latest/vaadin-grid/demo/sort.html#toc_1_sorting_the_data_sou)
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 https://github.com/vaadin/vaadin-grid/issues/206
Hi,
I removed my previous reply as you described exactly what I meant ! :)
Thanks a lot !!
Hi,
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::
setWidth("100%"); setSelectionMode(SelectionMode.SINGLE); setImmediate(true); setSizeFull(); setContainerDataSource(dataSource); setFooterVisible(true); for (Map.Entry<String, Object[]> entry : defHdrRow.entrySet()) { getDefaultHeaderRow().join(entry.getValue()).setText(entry.getKey()); } for (Map.Entry<String, Object[]> entry : prependHdrRow.entrySet()) { prependHeaderRow().join(entry.getValue()).setText(entry.getKey()); } }
Hi phani,
You’re using the Vaadin Framework Grid (Java version), whereas this topic was about the <vaadin-grid> custom element (JavaScript Web Component).
It would be better if you posted a new topic for your issue, on the "Framework UI" category. Thanks!