How to style headers in vaadin-grid - vaadin

I'm using a vaadin-grid with two header rows: one for the title of grouped columns and the other one for the real title of the column.
I want a vertical separator between the grouped columns.
For now, I use a classname generator on the first column of each group to add a left border :
grid.addComponentColumn(...)
.setHeader("My column")
.setClassNameGenerator(line -> "first-group-col")
with a dom-module included via JsImport:
import '#polymer/polymer/lib/elements/custom-style.js';
const documentContainer = document.createElement('template');
documentContainer.innerHTML = `
<dom-module id="my-grid-theme" theme-for="vaadin-grid">
<template>
<style>
.first-group-col {
border-left: 1px solid red;
}
</style>
</template>
</dom-module>`;
document.head.appendChild(documentContainer.content);
But the class '.first-group-col' doesn't appear on the header rows and I don't see how can I add a class on a header cell.
So how can I add a border on some column in the header rows ?
The number of columns in my grid is dynamic so I can't just use CSS to add the border on nth column.
I'm using Vaadin 14.
Regards,
Arnaud

I use a classname generator on the first column
Class name generator is applied for body cells, but not for the header cells.
You can style header by using something like follows, say you have Grid, with grid.addClassName("my-grid");
:host(.my-grid) [part="row"] [part~="header-cell"]{
padding-left: 3px;
color:brown;
background:var(--lumo-primary-color);
align-items:flex-start;
}
You can add the above css snipet to e.g. gridheader.css file in your frontend/styles folder and then import it
#CssImport(value = "./styles/gridheader.css", themeFor="vaadin-grid")

Related

Vaadin 8: How to display full-size picture in grid?

I am trying to display a list of persons in Vaadin 8 grid, including their photos (JPEGs in byte[]).
However, in the component column (see the code below) only the top of the picture is visible.
personsGrid.addComponentColumn(v -> {
if (v.getPhoto() != null) {
Image personsPhoto = new Image();
displayImage(personsPhoto, v.getPhoto());
return personsPhoto;
}
return new Image("", new ThemeResource("img/no-picture.jpg"));
});
Is there a way to show full-size picture in a grid?
How generally make grid rows adjust their heights depending on the content height?
As mentioned in the comment under the question, this cannot be achieved dynamically but you can explicitly set the height of the Grid Row using CSS.
Something along the lines of this should give you a steer in the right direction:
Java:
final Grid<SomeBean> grid = new Grid<>();
grid.addStyleName("custom-grid-style");
CSS:
.custom-grid-style .v-grid-body .v-grid-row .v-grid-cell {
min-height: 50px;
line-height: 50px;
}
And if you're unsure on where to make the CSS change, you need to add the #StyleSheet annotation on either the class you're editing or on the UI. And then the .css file must be in the same package location in your resources folder.
For example:
The class is in the package: com.example.components
Then your CSS file would be in: src/main/resources/com/example/components

Vaadin 13 TextArea Html Styling

I have two textAreas. For 1st one I want to make labels align row center, for the 2nd column flew-start. I give for every of them own Id and created separate html files for each. But when 1st textarea changes the 2nd one changes like the 1st, I can't give them their own label align.
How can I give for each own label alignment ?
You probably need to use textArea1.addClassName("my-text-area1") and then use something like follows:
<dom-module theme-for="vaadin-text-area" id="style-for-text-area1">
<template>
<style>
:host(.my-text-area1) [part="label"]{
... styles here ...
}
</style>
</template>
</dom-module>
And then do the same for the other text area.

How can I make a specific row unselectable in a Vaadin Grid with a mult-selection model?

I'm trying to disable the checkbox on a specific row based on some property of it's Bean (or just make the whole row generally unselectable), but I can't really see any method or property I could use to get a handle of the checkboxes on the left hand side added when using a multi-selection model or something as broad as disabling the whole row. Any thoughts on how this could be achieved, or where I should be looking?
You can use CSS to hide uncheckable rows. First set their styles using setRowStyleGenerator:
grid.setRowStyleGenerator(row -> {
boolean uncheckable = (Boolean)
row.getItem().getItemProperty("uncheckable").getValue();
return uncheckable ? "uncheckable-row" : "";
});
Then change styles in your .scss, they should look something like:
.v-grid-row.uncheckable-row td {
background: #b1b9d6 none repeat scroll 0 0;
}
.v-grid-row.uncheckable-row td:first-child {
visibility: hidden;
}
.v-grid-row.uncheckable-row.v-grid-row-selected > .v-grid-cell {
background-image: none;
border-color: #d4d4d4;
color: inherit;
text-shadow: inherit;
}
Here I hide the whole cell with checkbox (if hiding the content of td itself, user will still be available to select the row), use a different color for these rows and prevent them from being highlighted when "select all" checkbox is active. Surely, further styling is available. Since we only hide them from user, they still can be selected with grid.select() and located in grid.getSelectedRows() collection, you should filter them manually (by using some "uncheckable" property, as shown above).
It is not possible to disable checkbox on a specific row.
One solution is to use generated column and/or custom renderer.
if you are using twitter bootstrap as your responsive framework, you should be able to find that row and give it a class of ".inactive", and if that doesn't work you can always rig it but placing and absolute positioned box with a height and width of 100% inside of that row and z-index it to at least 250. That should make everything in that row un-clickable!

Vaadin label content too big

I have this piece of code
private VaadinLabel email,
this.email = new VaadinLabel();
this.informativoDab = new VaadinLabel();
HorizontalLayout row = new HorizontalLayout();
row.setWidth("100%");
row.addComponent(this.email);
row.addComponent(this.informativoDab);
And it gives me this:
When I actually want this:
It should be simple to do, but I've tried doing
this.email.setWidth("50%");
and it didn't work.
How can I do this with Vaadin Label, since I also need a hint to show the entire e-mail?
You should actually use "100%" as the label size as it should take all the space the layout gives for it, half in this case.
By default Vaadin will then wrapt the text on multiple lines. IIRC there isn't a built in css style name to do it, so you'll need to use CSS to disable wrapping and use the ellipsis to visualise overflown text. You could e.g. use "cut_text" style name (email.addStyleName("cut_text")) for your email label along with following css rules to your theme:
.cut_text {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
as #mstahv mentioned, add a style name to your label
email.addStyleName("cut_text");
and use that css he wrote
.cut_text {
white-space: nowrap;
text-overflow: ellipsis;
}
as for the whole email to be displayed, I would suggest adding a description. Then when user hovers the hidden email it will popup in a small tooltip.
email.setDescription("very_long#email.com");

Multiple rows in header in kendo mvc grid

How I can display the second word of header in column?
Now kendo grid doesnt show symbols which dont place in header
I want
Second
First
But now
Second Fi
Just add this CSS to allow the column header text to wrap when column width too small to display all words:
th.k-header{
white-space: normal !important;
}
DEMO

Resources