Skip to content

Commit

Permalink
fix(comp:table): fix itemHeight calc under virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Apr 14, 2022
1 parent 5976fd7 commit 0ac9be7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/components/table/src/main/MainTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default defineComponent({
dataSource={flattedData.value}
fullHeight={fullHeight}
height={(height || y) as number}
itemHeight={44}
itemHeight={47}
itemKey="rowKey"
itemRender={itemRender}
contentRender={contentRender}
Expand Down
3 changes: 2 additions & 1 deletion packages/components/table/src/main/body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { type VNodeTypes, computed, defineComponent, inject } from 'vue'

import { convertArray } from '@idux/cdk/utils'
import { ɵEmpty } from '@idux/components/_private/empty'

import { TABLE_TOKEN } from '../../token'
Expand Down Expand Up @@ -40,7 +41,7 @@ export default defineComponent({
children.push(...slots.default())
} else {
data.forEach((item, rowIndex) => {
children.push(...renderBodyRow(item, rowIndex, tableSlots, expandable.value))
children.push(...convertArray(renderBodyRow(item, rowIndex, tableSlots, expandable.value)))
})
}
} else {
Expand Down
15 changes: 5 additions & 10 deletions packages/components/table/src/main/body/RenderBodyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { TableColumnMergedExpandable } from '../../composables/useColumns'
import type { FlattedData } from '../../composables/useDataSource'
import type { TableBodyRowProps, TableColumnExpandable } from '../../types'
import type { Slots, VNodeChild, VNodeTypes } from 'vue'
import type { Slots, VNodeChild } from 'vue'

import { isFunction, isString } from 'lodash-es'

Expand All @@ -20,18 +20,13 @@ export function renderBodyRow(
rowIndex: number,
slots: Slots,
expandable: TableColumnMergedExpandable | undefined,
): VNodeTypes[] {
const nodes: VNodeTypes[] = []
): VNodeChild {
const { expanded, level, record, rowKey } = item
const rowProps = { key: rowKey, expanded, level, record, rowData: item, rowIndex, rowKey }
nodes.push(<BodyRow {...rowProps} />)
const rowNode = <BodyRow {...rowProps} />

if (expanded) {
const expandedContext = renderExpandedContext(rowProps, slots, expandable)
expandedContext && nodes.push(expandedContext)
}

return nodes
const expandedNode = expanded && renderExpandedContext(rowProps, slots, expandable)
return expandedNode ? [rowNode, expandedNode] : rowNode
}

function renderExpandedContext(props: TableBodyRowProps, slots: Slots, expandable: TableColumnExpandable | undefined) {
Expand Down

0 comments on commit 0ac9be7

Please sign in to comment.