Freeze Columns in Vaadin 7 table - vaadin

I have 20 columns in a vaadin 7 table, I want to freeze 4 columns so that whenever we scroll horizontally we should be able to see those frozen columns always.

There is no freeze columns feature in Vaadin 7 Table. But in newer Grid component you can set the X left most columns to be frozen with Grid.setFrozenColumnCount(..) methdod, see more here:
https://vaadin.com/api/framework/7.7.14/com/vaadin/ui/Grid.html#setFrozenColumnCount-int-
If you want to do something similar with Vaadin 7 Table, you probably need to do the following
Use two tables with the same data source Container
Wrap them inside e.g. CssLayout
Give z-index to other Table so that it is placed on top of the other in your theme CSS styles (Table.addStyleName("frozen-columns-table"))
Set the Table on top have only the "frozen" columns with setVisibleColumns(..) method
Set/style column widths etc. accordingly. The Table on top needs to be narrower than the bottom Table.
The above approach has its limitations and performance impacts, but could be a solution in some cases.

Related

Vaadin large table scrolls inside table (and underneath header) instead of scrolling page

Vaadin Version: 23.3.3
I have a fairly complex Vaadin table, ~100 rows, each of which contains ~12 columns, each column containing a layout with ~10 elements. The table is not lazy in any way, and is configured to show all rows at once.
It takes the browser 5+ seconds just to render the table after the request is complete (a topic for a different question) but even once the table is rendered I experience some weirdness when scrolling.
When holding the mouse outside the table, or using the scroll bar, the page always scrolls as expected. But when I hold the mouse inside the table I get inconsistent results. If I have first scrolled the page all the way to the bottom then there appears to be no issue regardless of mouse position. But If I have yet to scroll to the bottom, then the table scrolls in place, pushing rows underneath the header (see screenshot). It's as if the browser/vaadin is not yet completely aware of the size of the table?
Is there something I need to be doing to force vaadin to render the entire page?
Edit: Upon some further testing I noticed even stranger inconsistencies. My table cells have two possible layouts depending on user actions. One is simple, containing: div > span > span. The other is more complex, containing a div > span > span + vaadin-icon + tooltip. The issue only appears when the table is rendered with the "simple" layout. Something about the added vaadin-icon and tooltip seems to make vaadin draw the table without scroll issues.

Vaadin Grid: setAutoWidth(true) with recalculateColumnWidths() works only for visible rows in the grid

After I setup the a Grid with all the columns with setAutoWidth(true) and I execute grid.recalculateColumnWidths() this will auto-adapt the columns width with the content of the columns but only for the rows that are visible in the grid.
What happen is that scrolling rows in the grid I can find some cells with content larger than the content on the first visible rows and they were not auto-adapted and so the content is truncated (es FOO...)
Considering that I am using ListDataProvider, so all the rows are loaded into memory when I build the grid, why it is not calculating the right width for every column considering all the rows?
Is this a normal behaviour? It is possible to change it to consider all the rows when it is calculating the columns width?
I am using Vaadin version 14.
Thanks for the help
Yes,
this is the normal behaviour of the vaadin grid and is (at least for the 23.x) documented that way
https://vaadin.com/api/platform/23.2.6/com/vaadin/flow/component/grid/Grid.Column.html#setAutoWidth(boolean)
The relevant part, why it's not looking at all items in the grid is here:
For performance reasons the column width is calculated automatically only once when the grid items are rendered for the first time and the calculation only considers the rows which are currently rendered in DOM (a bit more than what is currently visible). If the grid is scrolled, or the cell content changes, the column width might not match the contents anymore.
You can however "retrigger" a width calculation
You can manually trigger the auto sizing behavior again by calling Grid.recalculateColumnWidths().

Move Grid save and cancel buttons from far right, maybe left justify

Is there a way in Vaadin 7 or Vaadin 8 to move the save/cancel buttons to under the last editor column? Or maybe to left justify them? Right now they are right justified under the last column. I would even take left justifying them under this same column. Visually, it is far from the last thing the users edited, so some users get confused. The way I am clarifying it for users right now is by making the Grid as narrow as possible, but it wastes screen real estate.
This will be very difficult in generic case, where column widths can be freely adjusted or their widths are automatically calculated by content. However if you set your columns fixed widths, so that you can make assumptions based on that within your specific application, there is a solution.
Just noting, that the Editor has div, with class name "v-grid-editor-footer", which has the same width as the Grid. So the editor footer does not have logical cells, that would be aligned with Grid's cells. And that is the challenge here. Furthermore the buttons you are refering to are wrapped in a child div of the previous one, with class name "v-grid-editor-buttons"
However you can try to add css rules in your theme in the following way.
.v-grid-editor-buttons {
position: relative;
left: -300px; // Adjust this value experimentally so that it fits your need
}
Below is a screenshot the css applied to Vaadin's Sampler.

change Vaadin grid/table orientation

How should I change the orientation of table or a grid? I want the headers to be on the left hand-side. Just 2 columns with header on the left side and value on the right side.
You cannot achieve such functionality with Table, but you can use Frozen Columns feature of Grid to emulate columns as first cells in each row like here http://demo.vaadin.com/sampler/#ui/grids-and-trees/grid/features

Keep Columns still while scrolling up and down. Excel 2010

Looking to keep Columns A-C stay still whole scrolling up and down. My worksheet has a lot of information on it and i need the first columns to stay still. I've tried freezing panes, but the columns only stay still when i scroll left and right, not up and down.
Can this be done?
To keep an area of a worksheet visible while you scroll to another area of the worksheet, you can lock specific rows or columns in one area by freezing or splitting panes.
When you freeze panes, you keep specific rows or columns visible when you scroll in the worksheet. For example, you might want to keep row and column labels visible as you scroll.
A solid line indicates that row 1 is frozen to keep column labels in place when you scroll.
When you split panes, you create separate worksheet areas that you can scroll within, while rows or columns in the non-scrolled area remain visible.
https://support.office.com/en-ca/article/Freeze-or-lock-rows-and-columns-3439cfe6-010c-4d2d-a3c9-d0e8ba62d724

Resources