@ -3,7 +3,7 @@
@@ -3,7 +3,7 @@
<!-- Mini hidden table for measuring row height and header height ( only when using dynamic height mode ) -- >
<!-- This mirrors the real table ' s cell rendering for accurate height estimation -- >
< div v-if ="shouldUseProbeRow" ref="miniTableRef" class="mini-table" aria-hidden="true" >
< div v-if ="miniTableData.length > 0" class="mini-table-inner" >
< div class = "mini-table-inner" >
<!-- Mini header row -- >
< div ref = "miniHeaderRef" class = "mini-row mini-header" >
< div
@ -16,26 +16,32 @@
@@ -16,26 +16,32 @@
< / div >
< / div >
<!-- Mini data rows -- >
< div v-for ="(rowData, rowIndex) in miniTableData" :key="rowIndex" class="mini-row" >
< div
v - for = "(column, columnIndex) in tableColumns || []"
: key = "column.key"
class = "mini-cell"
: style = "getMiniCellStyle(column)"
>
< MiniTableCell
: cellData = "lodash.get(rowData, String(column.dataKey || column.key))"
: columnIndex
: columns = "tableColumns"
: column
: rowData
: rowIndex
/ >
< div v-if ="miniTableData.length > 0" ref="miniTableRowsRef" class="mini-table-rows" >
< div v-for ="(rowData, rowIndex) in miniTableData" :key="rowIndex" class="mini-row" >
< div
v - for = "(column, columnIndex) in tableColumns || []"
: key = "column.key"
class = "mini-cell"
: style = "getMiniCellStyle(column)"
>
< MiniTableCell
: cellData = "lodash.get(rowData, String(column.dataKey || column.key))"
: columnIndex
: columns = "tableColumns"
: column
: rowData
: rowIndex
/ >
< / div >
< / div >
< / div >
< / div >
< / div >
< div v-if ="debug" class="debug-info" >
< div > Estimated Row Height : { { resolvedRowHeight } } < / div >
< div > Estimated Header Height : { { resolvedHeaderHeight } } < / div >
< / div >
< div ref = "myTableRef" class = "my-table" >
< el -auto -resizer >
< template # default = "{ height, width }" >
@ -47,7 +53,7 @@
@@ -47,7 +53,7 @@
: height = "resolvedHeight(height)"
: row - height = "prop.rowHeight"
: header - height = "resolvedHeaderHeight"
: estimated - row - height = "estimatedRowHeightToUse "
: estimated - row - height = "resolvedRowHeight "
: border = "border"
: row - key = "rowKey"
: class = "border ? 'has-border' : ''"
@ -88,6 +94,7 @@ import {
@@ -88,6 +94,7 @@ import {
nextTick ,
VNode ,
StyleValue ,
useTemplateRef ,
} from "vue" ;
import { useI18n } from "vue3-i18n" ;
import { Column , ElAutoResizer , ElTableV2 } from "element-plus" ;
@ -106,10 +113,10 @@ const slots = useSlots();
@@ -106,10 +113,10 @@ const slots = useSlots();
const { t } = useI18n ( ) ;
const { state } = useStore ( ) ;
const table = ref ( ) ;
const miniTableRef = ref ( ) ;
const miniHeaderRef = ref ( ) ;
const myTableRef = ref ( ) ; / / R e f e r e n c e t o . m y - t a b l e f o r R e s i z e O b s e r v e r
const miniTableRef = useTemplateRef ( "miniTableRef" ) ;
const miniHeaderRef = useTemplateRef ( "miniHeaderRef" ) ;
const miniTableRowsRef = useTemplateRef ( "miniTableRowsRef" ) ;
const myTableRef = useTemplateRef ( "myTableRef" ) ; / / R e f e r e n c e t o . m y - t a b l e f o r R e s i z e O b s e r v e r
const miniTableData = ref < any [ ] > ( [ ] ) ;
const estimatedRowHeight = ref < number | undefined > ( undefined ) ;
const estimatedHeaderHeight = ref < number | undefined > ( undefined ) ;
@ -129,16 +136,6 @@ type TimestampValue =
@@ -129,16 +136,6 @@ type TimestampValue =
type ? : "iso8601" | "unix" | "unixMillis" ;
} ;
interface TzDateTimeProps {
value : string | number ;
valueFormat ? : string ;
valueTz ? : string ;
displayFormat ? : string ;
locale ? : string ;
type ? : "iso8601" | "unix" | "unixMillis" ;
slot ? : boolean ;
}
interface TzDateTimeConfig {
valueFormat ? : string ;
valueTz ? : string ;
@ -184,6 +181,7 @@ interface Props {
@@ -184,6 +181,7 @@ interface Props {
rowHeight ? : number ;
estimatedRowHeight ? : number ;
headerHeight ? : number ;
debug ? : boolean ;
}
const prop = withDefaults ( defineProps < Props > ( ) , {
@ -226,7 +224,7 @@ const shouldUseProbeRow = computed(() => {
@@ -226,7 +224,7 @@ const shouldUseProbeRow = computed(() => {
/ / T h e e s t i m a t e d r o w h e i g h t t o p a s s t o e l - t a b l e - v 2
/ / O n l y u s e d w h e n r o w H e i g h t i s N O T s e t ( d y n a m i c h e i g h t m o d e )
const estimatedRowHeightToUse = computed ( ( ) => {
const resolvedRowHeight = computed ( ( ) => {
if ( prop . rowHeight !== undefined ) return undefined ; / / f i x e d h e i g h t m o d e , d o n ' t u s e e s t i m a t e d
if ( prop . estimatedRowHeight !== undefined ) return prop . estimatedRowHeight ; / / u s e r p r o v i d e d e s t i m a t e
return estimatedRowHeight . value ; / / u s e p r o b e - m e a s u r e d v a l u e
@ -248,22 +246,18 @@ watch(
@@ -248,22 +246,18 @@ watch(
if ( ! shouldUseProbeRow . value || ! data || data . length === 0 ) {
return ;
}
/ / U s e u p t o 5 r o w s f o r m i n i t a b l e
miniTableData . value = data . slice ( 0 , 5 ) ;
/ / U s e u p t o 3 r o w s f o r m i n i t a b l e
miniTableData . value = lodash . sampleSize ( data , 3 ) ;
/ / W a i t f o r m i n i t a b l e t o r e n d e r
await nextTick ( ) ;
/ / W a i t T W O f r a m e s f o r l a y o u t t o s e t t l e
await new Promise ( ( resolve ) => requestAnimationFrame ( resolve ) ) ;
await new Promise ( ( resolve ) => requestAnimationFrame ( resolve ) ) ;
/ / M e a s u r e h e a d e r h e i g h t
const headerEl = miniTableRef . value ? . querySelector ( ".mini-header" ) ;
const headerHeight = headerEl ? . offsetHeight ;
const { headerHeight , rowHeight } = estimateTableRowHeight ( ) ;
if ( headerHeight && headerHeight > 0 ) {
estimatedHeaderHeight . value = headerHeight ;
}
/ / M e a s u r e f i r s t r o w h e i g h t
const firstRow = miniTableRef . value ? . querySelector ( ".mini-row:not(.mini-header)" ) ;
const rowHeight = firstRow ? . offsetHeight ;
if ( rowHeight && rowHeight > 0 ) {
estimatedRowHeight . value = rowHeight ;
}
@ -271,6 +265,17 @@ watch(
@@ -271,6 +265,17 @@ watch(
{ immediate : true }
) ;
function estimateTableRowHeight ( ) {
const headerHeight = miniHeaderRef . value ? . offsetHeight ;
const tableRowsHeight = miniTableRowsRef . value ? . offsetHeight ;
const rowHeight =
tableRowsHeight && tableRowsHeight > 0 && miniTableData . value . length > 0
? lodash . round ( tableRowsHeight / miniTableData . value . length )
: undefined ;
return { headerHeight , rowHeight } ;
}
/ / S e t u p R e s i z e O b s e r v e r o n m o u n t ( n o t w i n d o w r e s i z e - t h a t c a u s e s f l i c k e r i n g )
onMounted ( ( ) => {
/ / R e s i z e h a n d l e r - m e a s u r e f i r s t , t h e n c l e a r a n d s e t i n s a m e m i c r o t a s k
@ -283,10 +288,7 @@ onMounted(() => {
@@ -283,10 +288,7 @@ onMounted(() => {
await new Promise ( ( resolve ) => requestAnimationFrame ( resolve ) ) ;
/ / M e a s u r e f i r s t w h i l e o l d v a l u e s s t i l l s e t
const headerEl = miniTableRef . value ? . querySelector ( ".mini-header" ) ;
const headerHeight = headerEl ? . offsetHeight ;
const firstRow = miniTableRef . value ? . querySelector ( ".mini-row:not(.mini-header)" ) ;
const rowHeight = firstRow ? . offsetHeight ;
const { headerHeight , rowHeight } = estimateTableRowHeight ( ) ;
const newHeader = headerHeight && headerHeight > 0 ? headerHeight : estimatedHeaderHeight . value ;
const newRow = rowHeight && rowHeight > 0 ? rowHeight : estimatedRowHeight . value ;
@ -554,6 +556,10 @@ const getMiniCellStyle = ({ width, minWidth, maxWidth, flexGrow, flexShrink }: C
@@ -554,6 +556,10 @@ const getMiniCellStyle = ({ width, minWidth, maxWidth, flexGrow, flexShrink }: C
< / script >
< style lang = "scss" scoped >
. debug - info {
font - size : 9 px ;
}
. list - table - v2 {
display : flex ;
flex - direction : column ;
@ -579,6 +585,12 @@ const getMiniCellStyle = ({ width, minWidth, maxWidth, flexGrow, flexShrink }: C
@@ -579,6 +585,12 @@ const getMiniCellStyle = ({ width, minWidth, maxWidth, flexGrow, flexShrink }: C
width : 100 % ;
}
. mini - table - rows {
display : flex ;
flex - direction : column ;
flex : 1 ;
}
. mini - row {
display : flex ;
align - items : stretch ;