@king-design/intact 2.0.17-beta.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/cascader/index.md +18 -0
- package/components/cascader/index.spec.ts +56 -0
- package/components/cascader/index.ts +35 -12
- package/components/cascader/index.vdt +9 -8
- package/components/cascader/useFields.ts +22 -0
- package/components/cascader/useFilterable.ts +23 -8
- package/components/cascader/useLabel.ts +7 -4
- package/components/cascader/useLoad.ts +4 -2
- package/components/code/demos/basic.md +1 -1
- package/components/colorpicker/index.md +16 -0
- package/components/colorpicker/index.ts +4 -0
- package/components/colorpicker/index.vdt +3 -2
- package/components/datepicker/index.md +11 -0
- package/components/dialog/index.spec.ts +2 -2
- package/components/dropdown/dropdown.ts +0 -1
- package/components/dropdown/item.ts +3 -2
- package/components/dropdown/usePosition.ts +9 -1
- package/components/editable/index.ts +17 -3
- package/components/editable/index.vdt +1 -0
- package/components/input/demos/autoRows.md +44 -0
- package/components/input/demos/password.md +12 -0
- package/components/input/demos/textarea.md +2 -2
- package/components/input/index.md +1 -0
- package/components/input/index.spec.ts +97 -1
- package/components/input/index.ts +17 -3
- package/components/input/index.vdt +29 -6
- package/components/input/styles.ts +18 -1
- package/components/input/useAutoRows.ts +65 -0
- package/components/input/useAutoWidth.ts +12 -3
- package/components/input/useShowPassword.ts +27 -0
- package/components/pagination/index.spec.ts +1 -1
- package/components/pagination/index.ts +1 -2
- package/components/portal.ts +4 -4
- package/components/position.ts +5 -1
- package/components/select/base.ts +3 -1
- package/components/select/base.vdt +2 -0
- package/components/select/index.md +11 -1
- package/components/table/cell.ts +4 -5
- package/components/table/demos/hideHeader.md +33 -0
- package/components/table/demos/pagination.md +53 -0
- package/components/table/index.md +22 -0
- package/components/table/index.spec.ts +73 -1
- package/components/table/row.ts +3 -3
- package/components/table/styles.ts +5 -0
- package/components/table/table.ts +29 -4
- package/components/table/table.vdt +21 -3
- package/components/table/useChecked.ts +21 -6
- package/components/table/useDisableRow.ts +3 -2
- package/components/table/useDraggable.ts +11 -8
- package/components/table/useGroup.ts +2 -0
- package/components/table/useMerge.ts +6 -3
- package/components/table/usePagination.ts +71 -0
- package/components/table/useRestRowStatus.ts +4 -1
- package/components/table/useTree.ts +4 -3
- package/components/timepicker/index.md +11 -0
- package/components/tooltip/demos/trigger.md +1 -1
- package/components/tooltip/index.md +1 -1
- package/components/tooltip/index.spec.ts +8 -5
- package/components/treeSelect/index.md +9 -0
- package/es/components/cascader/index.d.ts +22 -11
- package/es/components/cascader/index.js +9 -12
- package/es/components/cascader/index.spec.js +81 -0
- package/es/components/cascader/index.vdt.js +10 -8
- package/es/components/cascader/useFields.d.ts +2 -0
- package/es/components/cascader/useFields.js +18 -0
- package/es/components/cascader/useFilterable.d.ts +2 -1
- package/es/components/cascader/useFilterable.js +17 -6
- package/es/components/cascader/useLabel.d.ts +2 -1
- package/es/components/cascader/useLabel.js +4 -4
- package/es/components/cascader/useLoad.d.ts +2 -1
- package/es/components/cascader/useLoad.js +9 -7
- package/es/components/colorpicker/index.d.ts +2 -0
- package/es/components/colorpicker/index.js +7 -2
- package/es/components/colorpicker/index.vdt.js +3 -6
- package/es/components/dialog/index.spec.js +2 -2
- package/es/components/dropdown/dropdown.js +0 -1
- package/es/components/dropdown/item.js +3 -3
- package/es/components/dropdown/usePosition.js +8 -1
- package/es/components/editable/index.d.ts +1 -0
- package/es/components/editable/index.js +20 -6
- package/es/components/editable/index.vdt.js +2 -1
- package/es/components/input/index.d.ts +10 -2
- package/es/components/input/index.js +10 -3
- package/es/components/input/index.spec.js +169 -1
- package/es/components/input/index.vdt.js +26 -7
- package/es/components/input/styles.js +8 -3
- package/es/components/input/useAutoRows.d.ts +2 -0
- package/es/components/input/useAutoRows.js +79 -0
- package/es/components/input/useAutoWidth.js +13 -3
- package/es/components/input/useShowPassword.d.ts +7 -0
- package/es/components/input/useShowPassword.js +31 -0
- package/es/components/pagination/index.js +1 -3
- package/es/components/pagination/index.spec.js +2 -4
- package/es/components/portal.d.ts +6 -2
- package/es/components/portal.js +4 -3
- package/es/components/position.js +2 -1
- package/es/components/select/base.d.ts +2 -1
- package/es/components/select/base.js +3 -1
- package/es/components/select/base.vdt.js +3 -1
- package/es/components/table/cell.js +1 -6
- package/es/components/table/index.spec.js +130 -19
- package/es/components/table/row.d.ts +1 -1
- package/es/components/table/row.js +2 -1
- package/es/components/table/styles.js +1 -1
- package/es/components/table/table.d.ts +15 -0
- package/es/components/table/table.js +16 -7
- package/es/components/table/table.vdt.js +20 -6
- package/es/components/table/useChecked.d.ts +3 -2
- package/es/components/table/useChecked.js +23 -12
- package/es/components/table/useDisableRow.d.ts +2 -1
- package/es/components/table/useDisableRow.js +4 -4
- package/es/components/table/useDraggable.d.ts +3 -2
- package/es/components/table/useDraggable.js +11 -8
- package/es/components/table/useGroup.js +3 -0
- package/es/components/table/useMerge.d.ts +2 -1
- package/es/components/table/useMerge.js +5 -4
- package/es/components/table/usePagination.d.ts +8 -0
- package/es/components/table/usePagination.js +81 -0
- package/es/components/table/useTree.d.ts +2 -1
- package/es/components/table/useTree.js +3 -4
- package/es/components/tooltip/index.spec.js +9 -10
- package/es/index.d.ts +3 -3
- package/es/index.js +3 -3
- package/es/packages/kpc-react/__tests__/components/cascader.spec.d.ts +1 -0
- package/es/packages/kpc-react/__tests__/components/cascader.spec.js +79 -0
- package/es/site/data/components/dialog/demos/basic/react.js +4 -1
- package/es/site/data/components/input/demos/autoRows/index.d.ts +9 -0
- package/es/site/data/components/input/demos/autoRows/index.js +24 -0
- package/es/site/data/components/input/demos/autoRows/react.d.ts +8 -0
- package/es/site/data/components/input/demos/autoRows/react.js +62 -0
- package/es/site/data/components/input/demos/password/index.d.ts +5 -0
- package/es/site/data/components/input/demos/password/index.js +17 -0
- package/es/site/data/components/input/demos/password/react.d.ts +5 -0
- package/es/site/data/components/input/demos/password/react.js +41 -0
- package/es/site/data/components/input/demos/textarea/react.js +4 -2
- package/es/site/data/components/table/demos/hideHeader/index.d.ts +12 -0
- package/es/site/data/components/table/demos/hideHeader/index.js +30 -0
- package/es/site/data/components/table/demos/hideHeader/react.d.ts +11 -0
- package/es/site/data/components/table/demos/hideHeader/react.js +60 -0
- package/es/site/data/components/table/demos/pagination/index.d.ts +12 -0
- package/es/site/data/components/table/demos/pagination/index.js +35 -0
- package/es/site/data/components/table/demos/pagination/react.d.ts +16 -0
- package/es/site/data/components/table/demos/pagination/react.js +65 -0
- package/es/styles/fonts/ionicons.js +1 -1
- package/index.ts +3 -3
- package/package.json +4 -4
- package/styles/fonts/ionicons.ts +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 表格分页
|
|
3
|
+
order: 30
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
给组件添加`pagination`属性即可开启分页功能,`pagination`支持`Pagination`组件的全部属性,当分页信息改变时
|
|
7
|
+
会触发`changePage`事件
|
|
8
|
+
|
|
9
|
+
> 需要给Table设置rowKey属性,否则选择的行翻页后依然会保留选中状态,因为不设置key,则使用索引当key,
|
|
10
|
+
> 只要当前选中的索引在下一页存在,则会依然选中
|
|
11
|
+
|
|
12
|
+
```vdt
|
|
13
|
+
import {Table, TableColumn, Switch} from 'kpc';
|
|
14
|
+
|
|
15
|
+
<Table data={this.get('data')}
|
|
16
|
+
pagination
|
|
17
|
+
ref="table"
|
|
18
|
+
draggable
|
|
19
|
+
rowKey={item => item.name}
|
|
20
|
+
>
|
|
21
|
+
<TableColumn title="Name" key="name" />
|
|
22
|
+
<TableColumn title="IP" key="ip" />
|
|
23
|
+
</Table>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import {range, bind} from 'kpc/components/utils';
|
|
28
|
+
|
|
29
|
+
interface Props {
|
|
30
|
+
data: DataItem[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type DataItem = {
|
|
34
|
+
name: string
|
|
35
|
+
ip: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const data: DataItem[] = range(1, 20).map(item => {
|
|
39
|
+
return {
|
|
40
|
+
name: 'name ' + item,
|
|
41
|
+
ip: '127.0.0.' + item
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default class extends Component {
|
|
46
|
+
static template = template;
|
|
47
|
+
static defaults() {
|
|
48
|
+
return {
|
|
49
|
+
data,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
@@ -43,6 +43,8 @@ sidebar: doc
|
|
|
43
43
|
| widthStoreKey | 如果要保存表格拖动后的列宽信息,可以通过该属性设置保存到`localStorage`中的`key` | `string` | `undefined` |
|
|
44
44
|
| draggable | 表格行是否可拖动 | `boolean` | `false` |
|
|
45
45
|
| animation | 是否开启动效,默认开启。可以通过`true` `false`全部设置,或者通过数组单独设置行和列的动效 | `boolean` | `[boolean, boolean]` | `true` |
|
|
46
|
+
| hideHeader | 是否隐藏表头 | `boolean` | `false` |
|
|
47
|
+
| pagination | 是否支持分页 | `boolean` | `PaginationProps` | `false` |
|
|
46
48
|
|
|
47
49
|
```ts
|
|
48
50
|
import {Props} from 'intact';
|
|
@@ -74,6 +76,22 @@ type Position = {
|
|
|
74
76
|
type Collision = 'left' | 'top' | 'none'
|
|
75
77
|
|
|
76
78
|
export type Container = string | ((parentDom: Element, anchor: Node | null) => Element)
|
|
79
|
+
|
|
80
|
+
export interface PaginationProps {
|
|
81
|
+
size?: Sizes,
|
|
82
|
+
counts?: number | string,
|
|
83
|
+
total?: number,
|
|
84
|
+
value?: number,
|
|
85
|
+
limit?: number,
|
|
86
|
+
limits?: number[],
|
|
87
|
+
noBorder?: boolean,
|
|
88
|
+
simple?: boolean,
|
|
89
|
+
showTotal?: boolean,
|
|
90
|
+
showGoto?: boolean,
|
|
91
|
+
showLimits?: boolean,
|
|
92
|
+
disableBtn?: (page: number, limit: number) => boolean,
|
|
93
|
+
disablePage?: (page: number, limit: number) => boolean,
|
|
94
|
+
}
|
|
77
95
|
```
|
|
78
96
|
|
|
79
97
|
## TableColumn
|
|
@@ -145,3 +163,7 @@ export type TableColumnGroupItem = {
|
|
|
145
163
|
| clickRow | 点击某行触发 | `(data: T, index: number, key: TableRowKey) => void` |
|
|
146
164
|
| dragstart | 行拖动开始 | `(data: {key: TableRowKey, from: number}) => void` |
|
|
147
165
|
| dragend | 行拖动结束 | `(data: {key: TableRowKey, from: number, to: number}) => void` |
|
|
166
|
+
| checkRow | 手动选中某行触发 | `(data: T, index: number, key: TableRowKey) => void` |
|
|
167
|
+
| uncheckRow | 手动取消选中某行触发 | `(data: T, index: number, key: TableRowKey) => void` |
|
|
168
|
+
| checkAll | 手动全选触发 | `() => void` |
|
|
169
|
+
| uncheckAll | 手动取消全选触发 | `() => void` |
|
|
@@ -20,6 +20,7 @@ import MergeCellDemo from '~/components/table/demos/mergeCell';
|
|
|
20
20
|
import {Dropdown, DropdownMenu, DropdownItem} from '../dropdown';
|
|
21
21
|
import {Icon} from '../icon';
|
|
22
22
|
import {useChecked, AllCheckedStatus} from './useChecked';
|
|
23
|
+
import PaginationDemo from '~/components/table/demos/pagination';
|
|
23
24
|
|
|
24
25
|
describe('Table', () => {
|
|
25
26
|
afterEach(() => {
|
|
@@ -36,34 +37,49 @@ describe('Table', () => {
|
|
|
36
37
|
const spy = sinon.spy((v: number[]) => console.log(v));
|
|
37
38
|
table.on('$change:checkedKeys', spy);
|
|
38
39
|
|
|
40
|
+
const spyCheckRow = sinon.spy((data: any, index: number, key: string) => console.log('checkRow', data, index, key));
|
|
41
|
+
table.on('checkRow', spyCheckRow);
|
|
42
|
+
const spyUncheckRow = sinon.spy((data: any, index: number, key: string) => console.log('uncheckRow', data, index, key));
|
|
43
|
+
table.on('uncheckRow', spyUncheckRow);
|
|
44
|
+
const spyCheckAll = sinon.spy(() => console.log('checkAll'));
|
|
45
|
+
table.on('checkAll', spyCheckAll);
|
|
46
|
+
const spyUncheckAll = sinon.spy(() => console.log('uncheckAll'));
|
|
47
|
+
table.on('uncheckAll', spyUncheckAll);
|
|
48
|
+
|
|
39
49
|
// click row
|
|
40
50
|
const [tr1, tr2] = element.querySelectorAll<HTMLElement>('tbody tr');
|
|
41
51
|
tr1.click();
|
|
42
52
|
await wait();
|
|
43
53
|
expect(table.get('checkedKeys')).to.eql([0]);
|
|
54
|
+
expect(spyCheckRow.callCount).to.eql(1);
|
|
44
55
|
tr2.click();
|
|
45
56
|
await wait();
|
|
46
57
|
expect(table.get('checkedKeys')).to.eql([0, 1]);
|
|
47
58
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.All);
|
|
59
|
+
expect(spyCheckRow.callCount).to.eql(2);
|
|
60
|
+
expect(spyCheckAll.callCount).to.eq(0);
|
|
48
61
|
|
|
49
62
|
tr1.click();
|
|
50
63
|
await wait();
|
|
51
64
|
expect(table.get('checkedKeys')).to.eql([1]);
|
|
52
65
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.Indeterminate);
|
|
66
|
+
expect(spyUncheckRow.callCount).to.eql(1);
|
|
53
67
|
|
|
54
68
|
const all = element.querySelector('.k-checkbox') as HTMLElement;
|
|
55
69
|
all.click();
|
|
56
70
|
await wait();
|
|
57
71
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.All);
|
|
72
|
+
expect(spyCheckAll.callCount).to.eql(1);
|
|
58
73
|
all.click();
|
|
59
74
|
await wait();
|
|
60
75
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.None);
|
|
61
76
|
expect(table.get('checkedKeys')).to.eql([]);
|
|
77
|
+
expect(spyUncheckAll.callCount).to.eql(1);
|
|
62
78
|
|
|
63
79
|
expect(spy.callCount).to.eql(5);
|
|
64
80
|
// clear data of table should only trigger $change:checked event once, #407
|
|
65
81
|
all.click();
|
|
66
|
-
|
|
82
|
+
instance.set<{data: any[]}>('data', []);
|
|
67
83
|
await wait();
|
|
68
84
|
expect(spy.callCount).to.eql(7);
|
|
69
85
|
});
|
|
@@ -220,6 +236,13 @@ describe('Table', () => {
|
|
|
220
236
|
await wait();
|
|
221
237
|
expect(instance.get('multipleGroup')).to.eql({status: ['active', 'stopped']});
|
|
222
238
|
expect(table2.innerHTML).to.matchSnapshot();
|
|
239
|
+
|
|
240
|
+
// update group
|
|
241
|
+
instance.set('statusGroup', [{label: 'label', value: 'value'}]);
|
|
242
|
+
dispatchEvent(icon, 'click');
|
|
243
|
+
await wait(500);
|
|
244
|
+
const newDropdown= getElement('.k-table-group-dropdown')!;
|
|
245
|
+
expect(newDropdown.innerHTML).to.matchSnapshot();
|
|
223
246
|
});
|
|
224
247
|
|
|
225
248
|
it('fix columns', async () => {
|
|
@@ -559,4 +582,53 @@ describe('Table', () => {
|
|
|
559
582
|
await wait();
|
|
560
583
|
expect(update.callCount).to.eql(1);
|
|
561
584
|
});
|
|
585
|
+
|
|
586
|
+
it('pagination', async () => {
|
|
587
|
+
const [instance, element] = mount(PaginationDemo);
|
|
588
|
+
const table = instance.refs.table as Table;
|
|
589
|
+
const pagination = table.pagination.paginationRef;
|
|
590
|
+
const spy = sinon.spy();
|
|
591
|
+
|
|
592
|
+
table.on('changePage', spy);
|
|
593
|
+
|
|
594
|
+
// check all
|
|
595
|
+
table.checkAll();
|
|
596
|
+
expect(table.getCheckedData()).to.have.length(10);
|
|
597
|
+
|
|
598
|
+
// next page
|
|
599
|
+
table.set('pagination', { value: 2 });
|
|
600
|
+
(table as any).trigger('$receive:pagination');
|
|
601
|
+
await wait();
|
|
602
|
+
expect(table.getCheckedData()).to.have.length(0);
|
|
603
|
+
|
|
604
|
+
// check all again
|
|
605
|
+
table.checkAll();
|
|
606
|
+
expect(table.getCheckedData()).to.have.length(10);
|
|
607
|
+
|
|
608
|
+
// change limit
|
|
609
|
+
table.set('pagination', { value: 1, limit: 20 });
|
|
610
|
+
(table as any).trigger('$receive:pagination');
|
|
611
|
+
await wait();
|
|
612
|
+
expect(table.getCheckedData()).to.have.length(10);
|
|
613
|
+
|
|
614
|
+
// check all again
|
|
615
|
+
table.checkAll();
|
|
616
|
+
expect(table.getCheckedData()).to.have.length(20);
|
|
617
|
+
|
|
618
|
+
// change limit from pagination
|
|
619
|
+
pagination.value!.set('limit', 10);
|
|
620
|
+
await wait();
|
|
621
|
+
expect(table.getCheckedData()).to.have.length(10);
|
|
622
|
+
// FIXME: Pagination component should no trigger change event multiple times
|
|
623
|
+
// when we set value and limit at the same time
|
|
624
|
+
expect(spy.callCount).to.eql(4);
|
|
625
|
+
expect(spy.lastCall.lastArg).to.eql({value: 1, limit: 10});
|
|
626
|
+
|
|
627
|
+
// change page from pagination
|
|
628
|
+
await wait();
|
|
629
|
+
pagination.value!.changePage(2);
|
|
630
|
+
expect(table.getCheckedData()).to.have.length(0);
|
|
631
|
+
expect(spy.callCount).to.eql(5);
|
|
632
|
+
expect(spy.lastCall.lastArg).to.eql({value: 2, limit: 10});
|
|
633
|
+
});
|
|
562
634
|
});
|
package/components/table/row.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface TableRowProps {
|
|
|
25
25
|
index: number
|
|
26
26
|
disabled: boolean
|
|
27
27
|
allDisabled: boolean
|
|
28
|
-
onChangeChecked: (index: number, checked: boolean) => void
|
|
28
|
+
onChangeChecked: (index: number, checked: boolean, key: TableRowKey) => void
|
|
29
29
|
grid: TableGrid
|
|
30
30
|
selected: boolean
|
|
31
31
|
// hidden: boolean
|
|
@@ -91,8 +91,8 @@ export class TableRow extends Component<TableRowProps> {
|
|
|
91
91
|
|
|
92
92
|
@bind
|
|
93
93
|
onChangeChecked(v: boolean) {
|
|
94
|
-
const {index, onChangeChecked} = this.get();
|
|
95
|
-
onChangeChecked(index, v);
|
|
94
|
+
const {index, key, onChangeChecked} = this.get();
|
|
95
|
+
onChangeChecked(index, v, key);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
@bind
|
|
@@ -20,6 +20,8 @@ import {useStickyScrollbar} from './useStickyScrollbar';
|
|
|
20
20
|
import {useWidth} from './useWidth';
|
|
21
21
|
import {useScroll} from './useScroll';
|
|
22
22
|
import type {Events} from '../types';
|
|
23
|
+
import type {PaginationProps, PaginationChangeData} from '../pagination';
|
|
24
|
+
import { usePagination } from './usePagination';
|
|
23
25
|
|
|
24
26
|
export interface TableProps<
|
|
25
27
|
T = any,
|
|
@@ -60,12 +62,19 @@ export interface TableProps<
|
|
|
60
62
|
widthStoreKey?: string
|
|
61
63
|
draggable?: boolean
|
|
62
64
|
animation?: boolean | [boolean, boolean]
|
|
65
|
+
hideHeader?: boolean
|
|
66
|
+
pagination?: boolean | PaginationProps
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
export interface TableEvents<T = any, K extends TableRowKey = number> {
|
|
66
70
|
clickRow: [T, number, K]
|
|
67
71
|
dragstart: [{key: K, from: number}]
|
|
68
72
|
dragend: [{key: K, from: number, to: number}]
|
|
73
|
+
checkRow: [T, number, K]
|
|
74
|
+
uncheckRow: [T, number, K]
|
|
75
|
+
checkAll: []
|
|
76
|
+
uncheckAll: []
|
|
77
|
+
changePage: [PaginationChangeData]
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
export interface TableBlocks<T = unknown> {
|
|
@@ -118,6 +127,8 @@ const typeDefs: Required<TypeDefs<TableProps<unknown>>> = {
|
|
|
118
127
|
widthStoreKey: String,
|
|
119
128
|
draggable: Boolean,
|
|
120
129
|
animation: [Boolean, Array],
|
|
130
|
+
hideHeader: Boolean,
|
|
131
|
+
pagination: [Boolean, Object],
|
|
121
132
|
};
|
|
122
133
|
|
|
123
134
|
const defaults = (): Partial<TableProps> => ({
|
|
@@ -135,6 +146,11 @@ const events: Events<TableEvents> = {
|
|
|
135
146
|
clickRow: true,
|
|
136
147
|
dragstart: true,
|
|
137
148
|
dragend: true,
|
|
149
|
+
checkRow: true,
|
|
150
|
+
uncheckRow: true,
|
|
151
|
+
checkAll: true,
|
|
152
|
+
uncheckAll: true,
|
|
153
|
+
changePage: true,
|
|
138
154
|
};
|
|
139
155
|
|
|
140
156
|
export class Table<
|
|
@@ -149,7 +165,9 @@ export class Table<
|
|
|
149
165
|
static defaults = defaults;
|
|
150
166
|
static events = events;
|
|
151
167
|
|
|
152
|
-
|
|
168
|
+
// use public for unit test to get paginationRef
|
|
169
|
+
public pagination = usePagination();
|
|
170
|
+
private tree = useTree(this.pagination.data);
|
|
153
171
|
private columns = useColumns();
|
|
154
172
|
private scroll = useScroll();
|
|
155
173
|
private stickyHeader = useStickyHeader(this.scroll.callbacks);
|
|
@@ -169,20 +187,27 @@ export class Table<
|
|
|
169
187
|
this.scroll,
|
|
170
188
|
this.width.widthMap,
|
|
171
189
|
);
|
|
172
|
-
private disableRow = useDisableRow(
|
|
173
|
-
|
|
190
|
+
private disableRow = useDisableRow(
|
|
191
|
+
this.tree.loopData,
|
|
192
|
+
this.pagination.data,
|
|
193
|
+
);
|
|
194
|
+
private merge = useMerge(
|
|
195
|
+
this.columns.getCols,
|
|
196
|
+
this.pagination.data,
|
|
197
|
+
);
|
|
174
198
|
private checked = useChecked(
|
|
175
199
|
this.disableRow.getEnableKeys,
|
|
176
200
|
this.disableRow.getAllKeys,
|
|
177
201
|
this.disableRow.isDisabledKey,
|
|
178
202
|
this.merge.getGrid,
|
|
179
203
|
this.tree.loopData,
|
|
204
|
+
this.pagination.data,
|
|
180
205
|
);
|
|
181
206
|
private sortable = useSortable();
|
|
182
207
|
private expandable = useExpandable();
|
|
183
208
|
private selected = useSelected();
|
|
184
209
|
private resetRowStatus = useRestRowStatus(this.disableRow.getAllKeys);
|
|
185
|
-
private draggable = useDraggable();
|
|
210
|
+
private draggable = useDraggable(this.pagination.data);
|
|
186
211
|
private stickyScrollbar = useStickyScrollbar(
|
|
187
212
|
this.stickyHeader.elementRef,
|
|
188
213
|
this.scroll,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {eachChildren} from '../utils';
|
|
2
2
|
import {makeStyles} from './styles';
|
|
3
|
-
import {isStringOrNumber, isNull} from 'intact-shared';
|
|
3
|
+
import {isStringOrNumber, isNull, isObject, EMPTY_OBJ} from 'intact-shared';
|
|
4
4
|
import {getClassAndStyleForFixed} from './useFixedColumns';
|
|
5
5
|
import {Affix} from '../affix';
|
|
6
6
|
import {TableRow} from './row';
|
|
@@ -16,6 +16,7 @@ import {Tooltip} from '../tooltip';
|
|
|
16
16
|
import {AllCheckedStatus} from './useChecked';
|
|
17
17
|
import {context as ResizableContext} from './useResizable';
|
|
18
18
|
import {context as FixedColumnsContext} from './useFixedColumns';
|
|
19
|
+
import {Pagination} from '../pagination';
|
|
19
20
|
|
|
20
21
|
const {
|
|
21
22
|
data, children, className, fixHeader,
|
|
@@ -23,7 +24,8 @@ const {
|
|
|
23
24
|
rowClassName, group, sort, loading,
|
|
24
25
|
merge, childrenKey, indent, tooltipPosition,
|
|
25
26
|
tooltipContainer, showIndeterminate, resizable,
|
|
26
|
-
draggable, animation: _animation,
|
|
27
|
+
draggable, animation: _animation, hideHeader,
|
|
28
|
+
pagination,
|
|
27
29
|
} = this.get();
|
|
28
30
|
const animation = !Array.isArray(_animation) ? [_animation, _animation] : _animation;
|
|
29
31
|
const {columns, cols, maxRows, maxCols} = this.columns.getData();
|
|
@@ -64,7 +66,7 @@ const hasFixedLeft = getHasFixedLeft();
|
|
|
64
66
|
const {getAllCheckedStatus, toggleCheckedAll, getAllStatus, onChangeChecked} = this.checked;
|
|
65
67
|
const allCheckedStatus = getAllCheckedStatus();
|
|
66
68
|
const offsetMap = getOffsetMap();
|
|
67
|
-
const thead = (
|
|
69
|
+
const thead = hideHeader ? null : (
|
|
68
70
|
<TableContext.Provider value={checkType}>
|
|
69
71
|
<GroupContext.Provider value={{group, onChange: this.onChangeGroup}}>
|
|
70
72
|
<SortableContext.Provider value={{sort, onChange: this.sortable.onChange}}>
|
|
@@ -213,6 +215,13 @@ const {
|
|
|
213
215
|
onScroll: onScrollbarScroll,
|
|
214
216
|
tableActualWidth,
|
|
215
217
|
} = this.stickyScrollbar;
|
|
218
|
+
const {
|
|
219
|
+
value: pageValue,
|
|
220
|
+
limit: pageLimit,
|
|
221
|
+
onChange: onPageChange,
|
|
222
|
+
paginationRef,
|
|
223
|
+
} = this.pagination;
|
|
224
|
+
|
|
216
225
|
<div class={classNameObj} ref={elementRef}>
|
|
217
226
|
<div class="k-table-wrapper" style={style} ref={scrollRef}>
|
|
218
227
|
<Affix v-if={!isNull(stickHeader.value)}
|
|
@@ -231,6 +240,15 @@ const {
|
|
|
231
240
|
<template>{tbody}</template>
|
|
232
241
|
</table>
|
|
233
242
|
</div>
|
|
243
|
+
<Pagination v-if={pagination}
|
|
244
|
+
ref={paginationRef}
|
|
245
|
+
total={data ? data.length : 0}
|
|
246
|
+
size="small"
|
|
247
|
+
{...(isObject(pagination) ? pagination : EMPTY_OBJ)}
|
|
248
|
+
value={pageValue.value}
|
|
249
|
+
limit={pageLimit.value}
|
|
250
|
+
ev-change={onPageChange}
|
|
251
|
+
/>
|
|
234
252
|
<Transition name="k-fade">
|
|
235
253
|
<Spin v-if={loading} overlay size="small" class="k-table-spin" />
|
|
236
254
|
</Transition>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {createRef, useInstance, onMounted, onBeforeUnmount} from 'intact';
|
|
2
|
-
import {useState} from '../../hooks/useState';
|
|
2
|
+
import {useState, State, watchState} from '../../hooks/useState';
|
|
3
3
|
import type {Table, TableRowKey, TableCheckType} from './';
|
|
4
4
|
import {toggleArray} from '../utils';
|
|
5
5
|
import {useReceive} from '../../hooks/useReceive';
|
|
@@ -25,6 +25,7 @@ export function useChecked(
|
|
|
25
25
|
isDisabledKey: (key: TableRowKey) => boolean,
|
|
26
26
|
getGrid: () => TableGrid,
|
|
27
27
|
loopData: ReturnType<typeof useTree>['loopData'],
|
|
28
|
+
data: State<any[] | undefined>,
|
|
28
29
|
) {
|
|
29
30
|
const instance = useInstance() as Table<any, TableRowKey, TableCheckType>;
|
|
30
31
|
let allStatus: RowStatus[] = [];
|
|
@@ -36,8 +37,13 @@ export function useChecked(
|
|
|
36
37
|
function toggleChecked(key: TableRowKey, rowIndex: number) {
|
|
37
38
|
if (instance.get('checkType') === 'checkbox') {
|
|
38
39
|
instance.set('checkedKeys', toggleArray(instance.get('checkedKeys'), key));
|
|
40
|
+
|
|
41
|
+
// trigger check event for checkbox,
|
|
42
|
+
// radio check event trigger in onChangeChecked function
|
|
43
|
+
triggerEvent(isChecked(key), key, rowIndex);
|
|
39
44
|
} else {
|
|
40
45
|
if (isChecked(key)) return;
|
|
46
|
+
|
|
41
47
|
const grid = getGrid();
|
|
42
48
|
const gridRow = grid[rowIndex];
|
|
43
49
|
if (gridRow) {
|
|
@@ -46,7 +52,7 @@ export function useChecked(
|
|
|
46
52
|
rowIndex--;
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
|
-
onChangeChecked(rowIndex, true);
|
|
55
|
+
onChangeChecked(rowIndex, true, key);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
|
|
@@ -66,6 +72,7 @@ export function useChecked(
|
|
|
66
72
|
|
|
67
73
|
function toggleCheckedAll(v: boolean) {
|
|
68
74
|
instance.set('checkedKeys', getCheckedAllOrUncheckedAllKeys(v));
|
|
75
|
+
instance.trigger(v ? 'checkAll' : 'uncheckAll');
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
/**
|
|
@@ -93,9 +100,9 @@ export function useChecked(
|
|
|
93
100
|
function updateAllCheckedStatus() {
|
|
94
101
|
allStatus = [];
|
|
95
102
|
|
|
96
|
-
const {
|
|
103
|
+
const {rowKey, checkType, merge} = instance.get();
|
|
97
104
|
|
|
98
|
-
if (!data || !data.length) return;
|
|
105
|
+
if (!data.value || !data.value.length) return;
|
|
99
106
|
|
|
100
107
|
const allKeys = getAllKeys();
|
|
101
108
|
allKeys.forEach((key) => {
|
|
@@ -152,7 +159,7 @@ export function useChecked(
|
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
|
|
155
|
-
function onChangeChecked(rowIndex: number, v: boolean) {
|
|
162
|
+
function onChangeChecked(rowIndex: number, v: boolean, key: TableRowKey) {
|
|
156
163
|
// should check or uncheck all grouped rows
|
|
157
164
|
const checkType = instance.get('checkType');
|
|
158
165
|
const checkedKeys = (instance.get('checkedKeys') || []).slice();
|
|
@@ -190,16 +197,24 @@ export function useChecked(
|
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
instance.set('checkedKeys', checkedKeys);
|
|
200
|
+
|
|
201
|
+
// onChangeChecked will be called in clickRow and check in Row component
|
|
202
|
+
triggerEvent(v, key, rowIndex);
|
|
193
203
|
}
|
|
194
204
|
|
|
195
205
|
function getAllStatus() {
|
|
196
206
|
return allStatus;
|
|
197
207
|
}
|
|
198
208
|
|
|
209
|
+
function triggerEvent(isChecked: boolean, key: TableRowKey, rowIndex: number) {
|
|
210
|
+
instance.trigger(isChecked ? 'checkRow' : 'uncheckRow', data.value![rowIndex], rowIndex, key);
|
|
211
|
+
}
|
|
212
|
+
|
|
199
213
|
instance.on('$receive:children', updateAllCheckedStatus);
|
|
200
214
|
instance.on('$change:checkedKeys', updateAllCheckedStatus);
|
|
201
215
|
// for draggable
|
|
202
|
-
|
|
216
|
+
watchState(data, updateAllCheckedStatus);
|
|
217
|
+
// instance.on('$change:data', updateAllCheckedStatus);
|
|
203
218
|
|
|
204
219
|
instance.on('clickRow', (data: any, index: number, key: TableRowKey) => {
|
|
205
220
|
if (instance.get('rowCheckable') && instance.get('checkType') !== 'none') {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {useInstance} from 'intact';
|
|
2
2
|
import type {Table, TableRowKey, TableCheckType} from './table';
|
|
3
3
|
import type {useTree} from './useTree';
|
|
4
|
+
import { State, watchState } from '../../hooks/useState';
|
|
4
5
|
|
|
5
6
|
export function useDisableRow(
|
|
6
7
|
loopData: ReturnType<typeof useTree>['loopData'],
|
|
8
|
+
data: State<any[] | undefined>,
|
|
7
9
|
) {
|
|
8
10
|
const instance = useInstance() as Table<any, TableRowKey>;
|
|
9
11
|
let enabledKeys: TableRowKey[] = [];
|
|
@@ -47,8 +49,7 @@ export function useDisableRow(
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
instance.on('$receive:children', setDisabledKeys);
|
|
50
|
-
|
|
51
|
-
instance.on('$change:data', setDisabledKeys);
|
|
52
|
+
watchState(data, setDisabledKeys);
|
|
52
53
|
|
|
53
54
|
return {isDisabled, getEnableKeys, isDisabledKey, getAllKeys};
|
|
54
55
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {useInstance, nextTick} from 'intact';
|
|
2
2
|
import type {Table, TableRowKey} from './table';
|
|
3
|
-
import {useState} from '../../hooks/useState';
|
|
3
|
+
import {useState, State} from '../../hooks/useState';
|
|
4
4
|
import type {TableRow} from './row';
|
|
5
5
|
|
|
6
|
-
export function useDraggable() {
|
|
6
|
+
export function useDraggable(data: State<unknown[] | undefined>) {
|
|
7
7
|
const instance = useInstance() as Table<any, TableRowKey>;
|
|
8
8
|
const draggingKey = useState<TableRowKey | null>(null);
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ export function useDraggable() {
|
|
|
17
17
|
const key = tableRow.get('key');
|
|
18
18
|
draggingKey.set(key);
|
|
19
19
|
|
|
20
|
-
originData =
|
|
20
|
+
originData = data.value!;
|
|
21
21
|
|
|
22
22
|
instance.trigger('dragstart', {
|
|
23
23
|
key,
|
|
@@ -33,20 +33,23 @@ export function useDraggable() {
|
|
|
33
33
|
if (newIndex === draggingIndex) return;
|
|
34
34
|
|
|
35
35
|
// swap data
|
|
36
|
-
const
|
|
37
|
-
const item =
|
|
38
|
-
|
|
36
|
+
const newData = data.value!.slice();
|
|
37
|
+
const item = newData.splice(draggingIndex, 1)[0];
|
|
38
|
+
newData.splice(newIndex, 0, item);
|
|
39
39
|
|
|
40
40
|
draggingIndex = newIndex;
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
data.set(newData);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function onRowDragEnd(e: MouseEvent, tableRow: TableRow) {
|
|
46
46
|
e.preventDefault();
|
|
47
|
-
|
|
47
|
+
// revert to origin data, then set to new data to trigger animation
|
|
48
|
+
const newData = data.value;
|
|
49
|
+
data.set(originData);
|
|
48
50
|
|
|
49
51
|
nextTick(() => {
|
|
52
|
+
data.set(newData);
|
|
50
53
|
draggingKey.set(null);
|
|
51
54
|
instance.trigger('dragend', {
|
|
52
55
|
key: tableRow.get('key'),
|
|
@@ -17,6 +17,8 @@ export function useGroup() {
|
|
|
17
17
|
const keywords = useState<string>('');
|
|
18
18
|
const filteredGroup = useState<TableColumnGroupItem[] | undefined>(instance.get('group'));
|
|
19
19
|
|
|
20
|
+
instance.on('$receive:group', (group) => filteredGroup.set(group));
|
|
21
|
+
|
|
20
22
|
function onSelect(value: any, groupValue: any, onChange: ContextValue['onChange']) {
|
|
21
23
|
const {multiple, key} = instance.get();
|
|
22
24
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {useInstance, Props} from 'intact';
|
|
2
2
|
import type {Table, TableRowKey, TableCheckType} from './table';
|
|
3
3
|
import type {TableColumnProps} from './column';
|
|
4
|
+
import { State, watchState } from '../../hooks/useState';
|
|
4
5
|
|
|
5
6
|
export type TableMerge<T = any, CheckType = 'checkbox'> = (
|
|
6
7
|
row: T,
|
|
@@ -23,6 +24,7 @@ export type TableGrid = TableGridItem[][];
|
|
|
23
24
|
|
|
24
25
|
export function useMerge(
|
|
25
26
|
getCols: () => Props<TableColumnProps>[],
|
|
27
|
+
data: State<unknown[] | undefined>,
|
|
26
28
|
) {
|
|
27
29
|
const instance = useInstance() as Table<any, TableRowKey, TableCheckType>;
|
|
28
30
|
let grid: TableGrid = [];
|
|
@@ -30,11 +32,11 @@ export function useMerge(
|
|
|
30
32
|
function handleSpans() {
|
|
31
33
|
grid = [];
|
|
32
34
|
|
|
33
|
-
const {merge,
|
|
34
|
-
if (!data || !data.length || !merge) return;
|
|
35
|
+
const {merge, checkType} = instance.get();
|
|
36
|
+
if (!data.value || !data.value.length || !merge) return;
|
|
35
37
|
|
|
36
38
|
const cols = getCols();
|
|
37
|
-
data.forEach((data, rowIndex) => {
|
|
39
|
+
data.value.forEach((data, rowIndex) => {
|
|
38
40
|
const currentRow: TableGridItem[] = [];
|
|
39
41
|
grid.push(currentRow);
|
|
40
42
|
|
|
@@ -99,6 +101,7 @@ export function useMerge(
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
instance.on('$receive:children', handleSpans);
|
|
104
|
+
watchState(data, handleSpans);
|
|
102
105
|
|
|
103
106
|
return {getGrid};
|
|
104
107
|
}
|