Is there a way to get the absolute position of a c...
# kvision
l
Is there a way to get the absolute position of a component in KVision?
r
Do you have a absolutely positioned component (with
position = Position.ABSOLUTE
)? Or do you want to get a value computed somehow for a normal component?
You can use jquery bindings
l
I want to be able to calculate the height of the "rest of the viewport". That is to be able to set that height to force a tabulator table to fit and be re-sizable.
r
Shouldn't tabulator do this itself?
http://tabulator.info/docs/4.8/layout#virtual-dom look at the Table Resizing section
as far as I remember older versions of tabulator required a fixed height to be set
but current version should work with auto height
l
I am trying to get rid of the pagination and just get a scrollable table, which always fit on the screen when I resize the browser window.
If I do not specify the height the table extends outside the screen, and the whole page scrolls.
r
I'v tested tabulator with
Copy code
width = 100.vw
                height = 100.vh
and it perfectly fits the window and resize
l
Yes, but I have other panels above the table, och their height can change dynamically. I think it comes down to specifying the height of the tabulator as "100.perc of rest of viewport".
r
you can create a
VPanel
container with
height = 100.vh
to fit the screen size
and then put tabulator and other components inside like this:
Copy code
root("kvapp") {
            vPanel(alignItems = AlignItems.START, noWrappers = true) {
                height = 100.vh
                val ul = ul {
                    li("test")
                }
                button("add").onClick {
                    ul.add(Li("test"))
                }
                tabulator(data,
                    options = TabulatorOptions(
                        layout = Layout.FITCOLUMNS,
                        columns = listOf(
                        // ...
                        ), pagination = PaginationMode.LOCAL, paginationSize = 10, dataTree = true
                    ), types = setOf(TableType.BORDERED, TableType.STRIPED, TableType.HOVER)
                ) {
                    height = 100.perc
                }
            }
        }
the list and the button simulate changing size of other components
when the list grows the tabulator gets automatically smaller
and add a reasonable minHeight to tabulator so it wont disappear ;-)
l
Yes, this is exactly what I want. But, my problem is to set the height of the vPanel. In my application it is nested below and inside other components. I need some way to calculate its size.
r
to calculate the size (height) of any element it's probably easiest to use jQuery bindings:
Copy code
val ul = ul {
                    li("test")
                }
                button("add element").onClick {
                    ul.add(Li("test"))
                }
                button("print height").onClick {
                    console.log(ul.getElementJQuery()?.height())
                }
its perfectly documented here: https://api.jquery.com/height/
l
Thanks, will take a look.
That worked very well. Now it behaves exactly as I want. Thankt!