Why deprecate Column.setClassNameGenerator in 24.5.0?

After upgrading to vaadin 24.5.0.alpha1 I saw that Column.setClassNameGenerator is deprecated and Column.setPartNameGenerator should be used instead.

Is there a reason why we can’t have both?

I often use setClassNameGenerator to give the cell specific attributes like “no-padding” or “background”, also often combining them. Assigning these “attributes” via a part feels not right because part should only be one value and not multiple. A class is a better use case for this so I would love to keep this method.

Using part names has the benefit over using class names in that you don’t need to use shadow DOM styling / style injection to style the cells.

Instead, you can style the parts in your application theme with:

vaadin-grid::part(my-style-name) {
  background-color: lightblue;
}

It’s still possible to use shadow DOM styling with part names also if you change the selectors from .my-style-name to [part~=my-style-name].

[part~='my-style-name'] {
  background-color: lightblue;
}

would this also be then possible? :

Column.setPartNameGenerator(e -> "no-padding background")

with the styles:

vaadin-grid::part(no-padding) {
   padding:0
}
vaadin-grid::part(background) {
   background-color:var(--lumo-primary-color)
}

The background style would work fine like that.

The cell paddings in the grid are not on the cell elements directly however so you need to use the --vaadin-grid-cell-padding CSS variable for it:

vaadin-grid::part(no-padding) {
  --vaadin-grid-cell-padding: 0;
}