Vaadin grid table: how to disable the sort function and set the color of one column

I use a table Gridin Vaadin to represent data. For this, I am trying to figure out the following two questions:

1.) How to disable the sort function in the header of each column

2.) How to set the color of one column in a table Grid

+4
source share
2 answers

First of all, I found the Vaadin docs a good place to start looking for help. For the rest of the exercise, suppose we have Gridwith three simple columns c1, c2, and c3:

Grid grid = new Grid();
grid.addColumn("c1", String.class);
grid.addColumn("c2", String.class);
grid.addColumn("c3", String.class);



1.) How to disable the sort function in the header of each column

Go through each column and set its sort property to false:

for (Grid.Column column : grid.getColumns()) {
    column.setSortable(false);
}

, , :

grid.getColumn("c1").setSortable(false);



2.) Grid

, CSS theme:

@import "../valo/valo.scss";

@mixin mytheme {
  @include valo;
  // Insert your own theme rules here

  .v-grid-cell.green {
    background: #33BB00;
  }
}

CellStyleGenerator, :

grid.setCellStyleGenerator(new Grid.CellStyleGenerator() {
    @Override
    public String getStyle(Grid.CellReference cellReference) {
        if ("c1".equals(cellReference.getPropertyId())) {
            return "green";
        } else {
            return null;
        }
    }
});

- :

enter image description here

+7

Morfic good answer:

1.)

, (. appendColumn-method Grid). , getSortableContainerPropertyIds :

container = new BeanContainer<String, Dive>(Dive.class) {
            @Override
            public Collection<?> getSortableContainerPropertyIds() {
                LinkedList<Object> sortables = new LinkedList<Object>();
                return sortables;
            }
        };
+1

All Articles