import { Accessor, For, Match, Show, Switch, createEffect, createSignal } from "solid-js"
import { Cell } from "./Cell";
import { useTableContext } from ".";
import { TableStore, ColumnProps } from '.';
import { Colgroup } from "./Colgroup";
import { VirtualListCore } from "cui-virtual-list";
type BodyProps = {
data: TableStore,
onScroll: Function,
height?: number,
virtual?: boolean
}
type RowProps = {
store: TableStore,
data: any,
index: number,
ref?: any
}
export function Row (props: RowProps) {
const ctx: any = useTableContext();
const onRowClick = () => {
if (props.data._type === 'expandChildren') {
return;
}
// 设置了highlight属性才能进行高亮
if (ctx && ctx.highlight) {
ctx.onSelectRow(props.data);
}
}
const classList = () => ({
'cm-table-row': true,
'cm-table-row-ood': props.index % 2 === 0,
'cm-table-row-even': props.index % 2 !== 0,
'cm-table-row-selected': props.data._highlight
})
const rowStyle = () => ({
display: props.data._show ? '' : 'none',
})
return
{/* expand展开的内容 */}
|
|
{(column: ColumnProps, columnIndex: Accessor) => {
let [rowSpan, colSpan] = [1, 1];
if (ctx && ctx.spanMethod) {
const ret = ctx.spanMethod(props.data, column, props.index, columnIndex());
if (ret) {
[rowSpan, colSpan] = ret;
}
}
return
|
}}
}
function EmprtyRow (props: any) {
return
|
暂无数据
|
}
export function Body (props: BodyProps) {
let body: any;
const [height, setHeight] = createSignal();
const width = () => {
const columns = props.data.columns;
let total = 0;
columns.forEach((item: ColumnProps) => {
total += item._width || 0;
})
return total;
}
createEffect(() => {
// 数据改变也需要重刷
props.data.data;
const hh = props.data.headerSize.height;
if (props.virtual) {
const scrollElHeight = props.height ?? document.documentElement.clientHeight;
setHeight(scrollElHeight - hh);
} else {
setTimeout(() => {
const content = body.querySelector('.cm-table-body-wrap');
const contentH = content.getBoundingClientRect().height;
if (props.height && contentH > props.height - hh) {
const bodyH = props.height - hh;
setHeight(bodyH);
}
})
}
})
const handleScroll = () => {
props.onScroll(body.scrollLeft, body.clientWidth, body.scrollWidth);
}
let contentElement: any;
let bodyElement: any;
return
{(col: ColumnProps, index: Accessor) => {
return |
}}
|
{(params: any) => {
const rowData = params.item;
return
}}
{(col: ColumnProps, index: Accessor) => {
return |
}}
|
{(rowData: any, index: Function) => {
return
}}
}