Skip to content

Commit 298274c

Browse files
authored
fix(demo): fix table demo bug (#310)
* fix(demo): fix a demo bug 修复表格自定义操作的demo中,在全选所有数据后,取消第一页的勾选,到下一页再返回上一页,勾选还存在的问题。 * fix(demo): fix table demo bug 修复表格自定义操作的demo中,在全选所有数据后,取消第一页的勾选,到下一页再返回上一页,勾选还存在的问题。
1 parent b34784d commit 298274c

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

devui/data-table/demo/check-options/check-options.component.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import { originSource, SourceType } from '../mock-data';
1212
margin-top: 4px;
1313
}
1414
`]
15-
})
15+
})
1616
export class CheckOptionsComponent implements OnInit {
1717
@ViewChild(DataTableComponent, { static: true }) datatable: DataTableComponent;
18-
basicDataSource: Array<SourceType> = JSON.parse(JSON.stringify(originSource.slice(0, 6)));
18+
19+
bufferSource: Array<SourceType> = JSON.parse(JSON.stringify(originSource));
20+
basicDataSource: Array<SourceType> = JSON.parse(JSON.stringify(this.bufferSource.slice(0, 6)));
21+
1922
dataTableOptions = {
2023
columns: [
2124
{
@@ -96,10 +99,13 @@ export class CheckOptionsComponent implements OnInit {
9699
);
97100
this.totalDataChecked = true;
98101
this.allCheckedStatus = true;
102+
this.bufferSource = this.bufferSource.map(item => ({ $checked: true, ...item }));
99103
}
100104

101105
checkAllChange(checked: boolean) {
102106
this.allCheckedStatus = checked;
107+
108+
this.updateCurrentPageDataCheck(checked);
103109
}
104110

105111
checkPageData() {
@@ -110,6 +116,8 @@ export class CheckOptionsComponent implements OnInit {
110116
);
111117
this.totalDataChecked = false;
112118
this.allCheckedStatus = true;
119+
120+
this.updateCurrentPageDataCheck(true);
113121
}
114122

115123
onRowCheckChange(checked, rowIndex, nestedIndex, rowItem) {
@@ -121,27 +129,32 @@ export class CheckOptionsComponent implements OnInit {
121129
rowItem: rowItem,
122130
checked: checked
123131
});
132+
133+
const dataItem = this.bufferSource.find(item => item.id === rowItem.id);
134+
dataItem.$checked = checked;
135+
136+
if (checked) {
137+
this.totalDataChecked = this.basicDataSource.every(item => item.$checked);
138+
this.allCheckedStatus = this.bufferSource.every(item => item.$checked);
139+
} else {
140+
this.totalDataChecked = false;
141+
this.allCheckedStatus = false;
142+
}
124143
}
125144

126145
ngOnInit() {
127146
}
128147

129148
onPageIndexChange(pageIndex) {
130-
this.basicDataSource = JSON.parse(JSON.stringify(originSource.slice(pageIndex - 1, pageIndex + 5)));
131-
setTimeout(() => {
132-
if (this.totalDataChecked && this.allCheckedStatus) {
133-
this.datatable.setTableCheckStatus(
134-
{
135-
pageAllChecked: true
136-
}
137-
);
138-
} else {
139-
this.datatable.setTableCheckStatus(
140-
{
141-
pageAllChecked: false
142-
}
143-
);
144-
}
145-
});
149+
const startIndex = (pageIndex - 1) * this.pager.pageSize;
150+
const lastIndex = pageIndex * this.pager.pageSize;
151+
this.basicDataSource = this.bufferSource.slice(startIndex, lastIndex);
152+
}
153+
154+
private updateCurrentPageDataCheck(checked: boolean) {
155+
const startIndex = (this.pager.pageIndex - 1) * 6;
156+
for (let i = startIndex; i < this.pager.pageSize; i++) {
157+
this.bufferSource[i].$checked = checked;
158+
}
146159
}
147160
}

0 commit comments

Comments
 (0)