Simple extension to get, set and restore Grid scroll position in pixels and couple of other helpers.
Remember scroll position in TabSheet
Grid doesn't yet have server side getters and setters for scroll position. This extension adds those. In addition that it is able to cache the latest known scroll position. The main motivation for writing this add-on is to make Grid maintain its scroll position during Tab changes when used inside the TabSheet layout component. See demo application how it works.
Get actual column widths
There is also also getColumnWidth(..) method to get actual column widths of the Grid.
Compensate Column resizing side effects
Use getColumnResizeCompensationMode(ColumnResizeCompensationMode.RESIZE_GRID) method to get actual column widths of the Grid and setAutoResizeWidth(..) to Grid to automatically adjust width according to column widths. If automatic mode is not wanted or there is need to force Grid to resize due corner cases adjustGridWidth() API can be used.
Use getColumnResizeCompensationMode(ColumnResizeCompensationMode.RESIZE_COLUMN) to auto adjust the last Column to occupy the remaining space (if any).
See also: https://github.com/vaadin/framework/issues/10638
Get actual size of Grid
getWidth(), getHeight() get actual width and height of Grid
Events: GridRenderedEvent, GridResizedEvent, GridScrolledEvent and GridColumnsResizedEvent
There are corresponding addXXXListener methods. GridRenderedEvent is fired when initial column calculation is ready (real column widths are available after this). Other events should be useful also in various special cases.
Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.
- Added getColumnWidth(..) to get actual width of given column
- Added setAutoResizeWidth(..) to Grid automatically adjust width according to column widths.
- Apache License 2.0
- Vaadin 7.6+
- Vaadin 7.7+ in 1.0.0
- Vaadin 8.0+ in 2.0.0
- Vaadin 8.10 in 2.5.0
- Browser Independent