UNPKG

11.7 kBTypeScriptView Raw
1/// <reference types="react" />
2
3import React from 'react';
4import { CommonProps } from '../util';
5import { LoadingProps } from '../loading';
6import { AffixProps } from '../affix';
7
8interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
9 title?: any;
10}
11
12export interface ColumnProps extends HTMLAttributesWeak, CommonProps {
13 /**
14 * 指定列对应的字段,支持`a.b`形式的快速取值
15 */
16 dataIndex?: string;
17
18 /**
19 * 行渲染的逻辑
20 * value, rowIndex, record, context四个属性只可读不可被更改
21 * Function(value, index, record) => Element
22 */
23 cell?:
24 | React.ReactElement<any>
25 | React.ReactNode
26 | ((value: any, index: number, record: any) => any);
27
28 /**
29 * 表头显示的内容
30 * value, rowIndex, record, context四个属性只可读不可被更改
31 */
32 title?: React.ReactElement<any> | React.ReactNode | (() => any);
33
34 htmlTitle?: string;
35 /**
36 * 是否支持排序
37 */
38 sortable?: boolean;
39
40 /**
41 * 列宽,注意在锁列的情况下一定需要配置宽度
42 */
43 width?: number | string;
44
45 /**
46 * 单元格的对齐方式
47 */
48 align?: 'left' | 'center' | 'right';
49 sortDirections?: Array<'desc' | 'asc' | 'default'>;
50 /**
51 * 单元格标题的对齐方式, 不配置默认读取align
52 */
53 alignHeader?: 'left' | 'center' | 'right';
54
55 /**
56 * 生成标题过滤的菜单, 格式为`[{label:'xxx', value:'xxx'}]`
57 */
58 filters?: Array<any>;
59
60 /**
61 * 过滤的模式是单选还是多选
62 */
63 filterMode?: 'single' | 'multiple';
64
65 /**
66 * 是否支持锁列,可选值为`left`,`right`, `true`
67 */
68 lock?: boolean | string;
69
70 /**
71 * 是否支持列宽调整, 当该值设为truetable的布局方式会修改为fixed.
72 */
73 resizable?: boolean;
74 /**
75 * 是否支持异步列宽调整, 当该值设为truetable的布局方式会修改为fixed.
76 */
77 asyncResizable?: boolean;
78
79 /**
80 * header cell 横跨的格数,设置为0表示不出现此 th
81 */
82 colSpan?: number;
83
84 /**
85 * 设置该列单元格的word-break样式,对于id类、中文类适合用all,对于英文句子适合用word
86 */
87 wordBreak?: 'all' | 'word';
88}
89
90export class Column extends React.Component<ColumnProps, any> {}
91
92interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
93 title?: any;
94}
95
96export interface ColumnGroupProps extends HTMLAttributesWeak, CommonProps {
97 /**
98 * 表头显示的内容
99 */
100 title?: React.ReactElement<any> | React.ReactNode | (() => any);
101}
102
103export class ColumnGroup extends React.Component<ColumnGroupProps, any> {}
104
105export interface GroupHeaderProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
106 /**
107 * 行渲染的逻辑
108 */
109 cell?:
110 | React.ReactElement<any>
111 | React.ReactNode
112 | ((value: any, index: number, record: any) => any);
113
114 /**
115 * 是否在Children上面渲染selection
116 */
117 hasChildrenSelection?: boolean;
118
119 /**
120 * 是否在GroupHeader上面渲染selection
121 */
122 hasSelection?: boolean;
123
124 /**
125 * 当 dataSouce 里没有 children 时,是否使用内容作为数据
126 */
127 useFirstLevelDataWhenNoChildren?: boolean;
128}
129
130export class GroupHeader extends React.Component<GroupHeaderProps, any> {}
131
132export interface GroupFooterProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
133 /**
134 * 行渲染的逻辑
135 */
136 cell?:
137 | React.ReactElement<any>
138 | React.ReactNode
139 | ((value: any, index: number, record: any) => any);
140}
141
142export class GroupFooter extends React.Component<GroupFooterProps, any> {}
143
144export interface BaseTableProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
145 /**
146 * 样式类名的品牌前缀
147 */
148 prefix?: string;
149
150 /**
151 * 尺寸 small为紧凑模式
152 */
153 size?: 'small' | 'medium';
154
155 /**
156 * 自定义类名
157 */
158 className?: string;
159
160 /**
161 * 自定义内联样式
162 */
163 style?: React.CSSProperties;
164 columns?: Array<any>;
165 /**
166 * 表格元素的 table-layout 属性,设为 fixed 表示内容不会影响列的布局
167 */
168 tableLayout?: 'fixed' | 'auto';
169 /**
170 * 表格的总长度,可以这么用:设置表格总长度 、设置部分列的宽度,这样表格会按照剩余空间大小,自动其他列分配宽度
171 */
172 tableWidth?: number;
173 /**
174 * 表格展示的数据源
175 */
176 dataSource?: Array<any>;
177
178 /**
179 * 表格是否具有边框
180 */
181 hasBorder?: boolean;
182
183 /**
184 * 表格是否具有头部
185 */
186 hasHeader?: boolean;
187
188 /**
189 * 表格是否是斑马线
190 */
191 isZebra?: boolean;
192
193 /**
194 * 表格是否在加载中
195 */
196 loading?: boolean;
197
198 /**
199 * 自定义国际化文案对象
200 */
201 locale?: {
202 ok: string;
203 reset: string;
204 empty: string;
205 asc: string;
206 desc: string;
207 expanded: string;
208 folded: string;
209 filter: string;
210 selectAll: string;
211 };
212
213 /**
214 * 设置数据为空的时候的表格内容展现
215 */
216 emptyContent?: React.ReactNode;
217
218 /**
219 * dataSource当中数据的主键,如果给定的数据源中的属性不包含该主键,会造成选择状态全部选中
220 */
221 primaryKey?: string;
222}
223export interface TableProps extends React.HTMLAttributes<HTMLElement>, BaseTableProps {
224 /**
225 * 点击表格每一行触发的事件
226 */
227 onRowClick?: (record: any, index: number, e: React.MouseEvent) => void;
228
229 /**
230 * 悬浮在表格每一行的时候触发的事件
231 */
232 onRowMouseEnter?: (record: any, index: number, e: React.MouseEvent) => void;
233
234 /**
235 * 离开表格每一行的时候触发的事件
236 */
237 onRowMouseLeave?: (record: any, index: number, e: React.MouseEvent) => void;
238
239 /**
240 * 点击列排序触发的事件
241 */
242 onSort?: (dataIndex: string, order: string) => void;
243
244 /**
245 * 点击过滤确认按钮触发的事件
246 */
247 onFilter?: (filterParams: any) => void;
248
249 /**
250 * 重设列尺寸的时候触发的事件
251 */
252 onResizeChange?: (dataIndex: string, value: number) => void;
253
254 /**
255 * 设置每一行的属性,如果返回值和其他针对行操作的属性冲突则无效。
256 */
257 getRowProps?: (record: any, index: number) => any;
258 rowProps?: (record: any, index: number) => any;
259
260 /**
261 * 设置单元格的属性,通过该属性可以进行合并单元格
262 */
263 getCellProps?: (rowIndex: number, colIndex: number, dataIndex: string, record: any) => any;
264 cellProps?: (rowIndex: number, colIndex: number, dataIndex: string, record: any) => any;
265
266 /**
267 * 自定义 Loading 组件
268 * 请务必传递 props, 使用方式: loadingComponent={props => <Loading {...props}/>}
269 */
270 loadingComponent?: (props: LoadingProps) => React.ReactNode;
271
272 /**
273 * 当前过滤的的keys,使用此属性可以控制表格的头部的过滤选项中哪个菜单被选中,格式为 {dataIndex: {selectedKeys:[]}}
274 * 示例:
275 * 假设要控制dataIndex为id的列的过滤菜单中key为one的菜单项选中
276 * `<Table filterParams={{id: {selectedKeys: ['one']}}}/>`
277 */
278 filterParams?: { [propName: string]: any };
279
280 /**
281 * 当前排序的字段,使用此属性可以控制表格的字段的排序,格式为{dataIndex: 'asc'}
282 */
283 sort?: { [propName: string]: any };
284
285 /**
286 * 自定义排序按钮,例如上下排布的: `{desc: <Icon style={{top: '6px', left: '4px'}} type={'arrow-down'} size="small" />, asc: <Icon style={{top: '-6px', left: '4px'}} type={'arrow-up'} size="small" />}`
287 */
288 sortIcons?: { desc?: React.ReactNode; asc?: React.ReactNode };
289
290 /**
291 * 额外渲染行的渲染函数
292 */
293 expandedRowRender?: (record: any, index: number) => React.ReactElement<any>;
294 rowExpandable?: (record: any) => boolean;
295
296 /**
297 * 额外渲染行的缩进,包含两个数字,第一个数字为左侧缩进,第二个数字为右侧缩进
298 */
299 expandedRowIndent?: [number, number];
300
301 /**
302 * 默认情况下展开的渲染行或者Tree, 传入此属性为受控状态
303 */
304 openRowKeys?: Array<any>;
305
306 /**
307 * 是否显示点击展开额外渲染行的+号按钮
308 */
309 hasExpandedRowCtrl?: boolean;
310
311 /**
312 * 设置额外渲染行的属性
313 */
314 getExpandedColProps?: <IRecord extends any = any>(
315 record: IRecord,
316 index: number
317 ) => object | Record<string | number, any>;
318
319 /**
320 * 在额外渲染行或者Tree展开或者收起的时候触发的事件
321 */
322 onRowOpen?: (
323 openRowKeys: Array<any>,
324 currentRowKey: string,
325 expanded: boolean,
326 currentRecord: any
327 ) => void;
328
329 /**
330 * 点击额外渲染行触发的事件
331 */
332 onExpandedRowClick?: (record: any, index: number, e: React.MouseEvent) => void;
333
334 /**
335 * 表头是否固定,该属性配合maxBodyHeight使用,当内容区域的高度超过maxBodyHeight的时候,在内容区域会出现滚动条
336 */
337 fixedHeader?: boolean;
338
339 /**
340 * 最大内容区域的高度,在`fixedHeader`为`true`的时候,超过这个高度会出现滚动条
341 */
342 maxBodyHeight?: number | string;
343
344 /**
345 * 是否启用选择模式
346 */
347 rowSelection?: {
348 getProps?: (record: any, index: number) => void;
349 onChange?: (selectedRowKeys: Array<any>, records: Array<any>) => void;
350 onSelect?: (selected: boolean, record: any, records: Array<any>) => void;
351 onSelectAll?: (selected: boolean, records: Array<any>) => void;
352 selectedRowKeys?: Array<any>;
353 mode?: 'single' | 'multiple';
354 titleProps?: () => any;
355 columnProps?: () => any;
356 titleAddons?: () => any;
357 };
358
359 /**
360 * 表头是否是sticky
361 */
362 stickyHeader?: boolean;
363
364 /**
365 * 距离窗口顶部达到指定偏移量后触发
366 */
367 offsetTop?: number;
368
369 /**
370 * affix组件的的属性
371 */
372 affixProps?: AffixProps;
373
374 /**
375 * 在tree模式下的缩进尺寸, 仅在isTree为true时候有效
376 */
377 indent?: number;
378
379 /**
380 * 开启Table的tree模式, 接收的数据格式中包含children则渲染成tree table
381 */
382 isTree?: boolean;
383
384 /**
385 * 是否开启虚拟滚动
386 */
387 useVirtual?: boolean;
388
389 /**
390 * 滚动到指定行
391 */
392 scrollToRow?: number;
393
394 /**
395 * 设置行高
396 */
397 rowHeight?: number | (() => any);
398
399 /**
400 * 在内容区域滚动的时候触发的函数
401 */
402 onBodyScroll?: (start: number) => void;
403
404 /**
405 * 开启时,getExpandedColProps() / getRowProps() / expandedRowRender() 的第二个参数 index (该行所对应的序列) 将按照01,2,3,4...的顺序返回,否则返回真实index(0,2,4,6... / 1,3,5,7...)
406 */
407 expandedIndexSimulate?: boolean;
408 /**
409 * 在 hover 时出现十字参考轴,适用于表头比较复杂,需要做表头分类的场景。
410 */
411 crossline?: boolean;
412
413 /**
414 * 虚拟滚动时向前保留渲染的行数
415 * @defaultValue 10
416 */
417 keepForwardRenderRows?: number;
418}
419
420export default class Table extends React.Component<TableProps, any> {
421 static Column: typeof Column;
422 static ColumnGroup: typeof ColumnGroup;
423 static GroupHeader: typeof GroupHeader;
424 static GroupFooter: typeof GroupFooter;
425 static StickyLock: typeof Table;
426 static Base: typeof Table;
427}