sorting column in grid

Hello Vaadin Team,
Im using latest vaadin version
i want to apply sorting on my column
the sorting is based on icon present in the row or not
so i tried setSorting(true) but it not giving me the result
do any one know how to sort using compartor

Here is my code example

public class MyTable extends Grid<Map<String, String>>{

public MyTable(MyTableModel myTableModel) {


private void addColumnToContainer() {

addColumn(new ComponentRenderer<>(map ->{
if(“true”.equals(map.get(“verified”))) {
Div div = new Div(VaadinIcon.CHECK_CIRCLE.create());
return div;
return new Span();
})).setComparator((p1,p2)-> p1.get(“verified”).compareTo(p2.get(“verified”)))


whats wrong with my code the sorting is not working with this code
Can anyone help me?

How should Vaadin know how to sort components? You have to also supply a comparator

If I remember correctly the setComparator has to be applied after the setSortable (NVM… this isn’t the case anymore)

If you don’t know how to create a comparator in java, its best to isolate the problem and once you can can compare two strings correctly in a test class, apply that logic here.

Even logs are not getting printed in comparator any idea why

My comparator
setComparator((p1,p2)-> {
boolean obj1 = Boolean.valueOf(p1.get(“visited”));
boolean obj2 = Boolean.valueOf(p2.get(“visited”)); System.out.println(“Obj1 Obj2 " +obj1+” "+obj2);
return (obj1 == obj2) ? 0 : (obj1 ? 1 : -1); })

Just a guess: you are using a non-inmemory data provider and therefore comparator are not used and instead passed the Backend / lazy loading provider

Is there any alternative way to sort or make comparator work

Use ListDataProvider or implement the sorting callbacks in your Backend

I’m using callbackdataprovider is it the reason for it
Is it still not possible to sort a grid using a comparator when you’re using a CallbackDataProvider?

Correct, like Tatu said in the comment.