[Feature Request] Data Table - dynamic height, remainder of parent
Problem to solve
As the Data Table is table based, it is problematic to apply styles to make it "fill the remaining parent height". this can easily be done with flexgrid. but no luck here.
there is a fixed header prop and a height prop on the Data Table, which is a good start. but even better would be if the height could be dynamic and measure where the bottom of the parent container is.
Proposed solution
I have no idea. a JS solution to measure how high the component should be (?)
Does anyone have a solution for this? Lets say I want to put my fixed-header non-paginated table into a card with relative height. How to do this properly? The only solution I have come up with is guessing the height of the card (with vh) and setting the tables height to somewhat less than that. But this is not even a solution, because for some reason the footer is not calculated into the height so it overflows from lets say a card.
I've created an "AutoSizer" component which measures top of content to bottom of window.
<template>
<div ref="root">
<slot :height="height"></slot>
</div>
</template>
<script lang="js">
import {ref, onMounted, onUnmounted} from "@vue/composition-api";
import Vue from "vue";
import _ from "underscore";
export default {
name: "AutoSizer",
setup(props,ctx) {
const height = ref(0);
function ressized() {
const windowHeight = window.innerHeight;
const root = ctx.refs.root;
if (!root) {
return;
}
const top = root.getBoundingClientRect().top;
height.value = windowHeight - top - 20;
ctx.emit("height",height.value);
}
onMounted(() => {
window.addEventListener("resize", _.debounce(ressized, 50, false), true);
Vue.nextTick(() => {
ressized();
});
});
onUnmounted(() => {
window.removeEventListener("resize", ressized);
});
return {
height
}
}
}
</script>
I use this to size my data tables accordingly. The slot has a height property which can be used to set on the datatable.
like so:
<AutoSizer>
<template #default="{height}">
<DataTable
fixed-header
:height="height"
....
This does not take into account that you might want reminder of some other component, it just measures from top of table to bottom of window, bit I assume it can be adjusted to match the required usecase.
https://play.vuetifyjs.com/#eNqVlm1v2jAQx7/KKWsFSCWE8FAa0UpVu4eue7G3EyDVJAashiRyHDaG+O47EycOwS3dG4LPd/Hv/ne5ZLKzUu537pPE3mTU8qyxoOskJILeTSOA8aZNkuTw97Dw40gQFlGuTLmR8ABWlC1X4nZqjRxnaoEfkjTFVdBehPTP1Cr9DxEBEaQtyDyk2gzgrSgJKJdh6t/UOtpnyCZ3N4yLjISPNE0pFzWv4mQa0g0RL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