1 |
|
2 |
|
3 | import React from 'react';
|
4 | import { CommonProps } from '../util';
|
5 | import { LoadingProps } from '../loading';
|
6 | import { AffixProps } from '../affix';
|
7 |
|
8 | interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
|
9 | title?: any;
|
10 | }
|
11 |
|
12 | export interface ColumnProps extends HTMLAttributesWeak, CommonProps {
|
13 | |
14 |
|
15 |
|
16 | dataIndex?: string;
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
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 | * 是否支持列宽调整, 当该值设为true,table的布局方式会修改为fixed.
|
72 | */
|
73 | resizable?: boolean;
|
74 | /**
|
75 | * 是否支持异步列宽调整, 当该值设为true,table的布局方式会修改为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 |
|
90 | export class Column extends React.Component<ColumnProps, any> {}
|
91 |
|
92 | interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
|
93 | title?: any;
|
94 | }
|
95 |
|
96 | export interface ColumnGroupProps extends HTMLAttributesWeak, CommonProps {
|
97 | /**
|
98 | * 表头显示的内容
|
99 | */
|
100 | title?: React.ReactElement<any> | React.ReactNode | (() => any);
|
101 | }
|
102 |
|
103 | export class ColumnGroup extends React.Component<ColumnGroupProps, any> {}
|
104 |
|
105 | export 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 |
|
130 | export class GroupHeader extends React.Component<GroupHeaderProps, any> {}
|
131 |
|
132 | export 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 |
|
142 | export class GroupFooter extends React.Component<GroupFooterProps, any> {}
|
143 |
|
144 | export 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 | }
|
223 | export 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 |
|
268 |
|
269 |
|
270 | loadingComponent?: (props: LoadingProps) => React.ReactNode;
|
271 |
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | filterParams?: { [propName: string]: any };
|
279 |
|
280 | |
281 |
|
282 |
|
283 | sort?: { [propName: string]: any };
|
284 |
|
285 | |
286 |
|
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 |
|
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 |
|
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 |
|
336 |
|
337 | fixedHeader?: boolean;
|
338 |
|
339 | |
340 |
|
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 |
|
361 |
|
362 | stickyHeader?: boolean;
|
363 |
|
364 | |
365 |
|
366 |
|
367 | offsetTop?: number;
|
368 |
|
369 | |
370 |
|
371 |
|
372 | affixProps?: AffixProps;
|
373 |
|
374 | |
375 |
|
376 |
|
377 | indent?: number;
|
378 |
|
379 | |
380 |
|
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 |
|
406 |
|
407 | expandedIndexSimulate?: boolean;
|
408 | |
409 |
|
410 |
|
411 | crossline?: boolean;
|
412 |
|
413 | |
414 |
|
415 |
|
416 |
|
417 | keepForwardRenderRows?: number;
|
418 | }
|
419 |
|
420 | export 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 | }
|