React-VTable自定义组件
自定义单元格组件
为了方便react开发者快速实现自定义单元格内容,React-VTable 提供了封装组件并在单元格中使用的能力。
组件用法
使用自定义单元格组件时,需要使用react 18版本
自定义单元格组件在自定义布局的基础上封装而成,用法类似于自定义布局。在ListColumn中使用组件,自定义组件需要传入role属性,用于标识该组件为自定义单元格组件;其中custom-layout组件会在表格内容部分生效,header-custom-layout组件会在表格表头部分生效。每列中最多只能有一个custom-layout组件,最多只能有一个header-custom-layout组件。
<ListTable records={records}> <ListColumn field={'bloggerName'} title={'bloggerName'} width={330} disableHover={true}> <CustomLayoutComponent role={'custom-layout'} info={bodyInfo}/> <HeaderCustomLayoutComponent role={'header-custom-layout'} info={headerInfo}/> </ListColumn> // ...... </ListTable>
组件封装
默认属性
在组件中,除了用户定义的属性外,与自定义布局一样,react-vtable还提供了一些默认属性供组件使用
interface CustomLayoutProps { table: ListTable; // 表格实例 row: number; // 行号 col: number; // 列号 value: FieldData; // 单元格展示数据 dataValue: FieldData; // 单元格原始数据 rect?: RectProps; // 单元格布局信息 } const CustomLayoutComponent = (props: CustomLayoutProps & UserProps) => { const { table, row, col, rect, text } = props; // ...... }