-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(module:table): radio selection type #8823
Open
ParsaArvanehPA
wants to merge
42
commits into
NG-ZORRO:master
Choose a base branch
from
ParsaArvanehPA:feature/radio-selection-in-table
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
5c11a42
fix(module:tabs): wrong cursor
ParsaArvanehPA aac33c4
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA f7525f5
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 8a974b9
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA e5276bb
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 0f989fe
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA ec35a90
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 6ec6fe1
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 988985b
feat(module:table): radio selection type
ParsaArvanehPA 5e4dd2a
feat(module:table): radio selection type
ParsaArvanehPA 5d1e384
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA d81339e
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 2284767
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 0ac094d
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 59d40a5
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 82afabb
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 5cad626
feat(module:table): radio selection type
ParsaArvanehPA 8166519
feat(module:table): radio selection type
ParsaArvanehPA 3a46b38
feat(module:table): radio selection type
ParsaArvanehPA 11b7fc8
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA ec24a0b
Merge branch 'refs/heads/master' into feature/radio-selection-in-tables
ParsaArvanehPA 8705669
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 19dd9b5
Merge branch 'refs/heads/master' into feature/radio-selection-in-tables
ParsaArvanehPA 105ad16
feat(module:table): radio selection type
ParsaArvanehPA 0e963ac
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 2bb0cd9
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 674a373
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 124d3ac
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 413ac69
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 5bee081
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 2569a26
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 1e6cc5e
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA e0eb45a
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA aa3571f
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA eb50945
Merge branch 'refs/heads/master' into feature/radio-selection-in-tables
ParsaArvanehPA 44d9311
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA ca70f46
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 5227c13
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 590f22c
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 1577205
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA 912db8e
Merge branch 'NG-ZORRO:master' into master
ParsaArvanehPA ccbadd6
Merge branch 'master' into feature/radio-selection-in-table
ParsaArvanehPA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 2 | ||
title: | ||
en-US: Selection | ||
zh-CN: 可选择 | ||
--- | ||
|
||
## zh-CN | ||
|
||
第一列是联动的选择框。可以通过 `nzRowSelectionType` 属性指定选择类型,默认为 `checkbox`。 | ||
|
||
## en-US | ||
|
||
Rows can be selectable by making first column as a selectable column. You can use `nzRowSelectionType` to set selection type. Default is `checkbox`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { NzRowSelectionType } from 'ng-zorro-antd/table'; | ||
|
||
interface ItemData { | ||
id: number; | ||
name: string; | ||
age: number; | ||
address: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'nz-demo-table-selection', | ||
template: ` | ||
<nz-radio-group [(ngModel)]="rowSelectionType" (ngModelChange)="resetSelectedValues()"> | ||
<label nz-radio nzValue="checkbox">checkbox</label> | ||
<label nz-radio nzValue="radio">radio</label> | ||
</nz-radio-group> | ||
|
||
<nz-table #rowSelectionTable [nzData]="listOfData" (nzCurrentPageDataChange)="onCurrentPageDataChange($event)"> | ||
<thead> | ||
<tr> | ||
<ng-container *ngIf="rowSelectionType === 'radio'"> | ||
<th nzShowRowSelection [nzRowSelectionType]="'radio'"> </th> | ||
</ng-container> | ||
<ng-container *ngIf="rowSelectionType === 'checkbox'"> | ||
<th [(nzChecked)]="checked" [nzIndeterminate]="indeterminate" (nzCheckedChange)="onAllChecked($event)"></th> | ||
</ng-container> | ||
<th>Name</th> | ||
<th>Age</th> | ||
<th>Address</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let data of rowSelectionTable.data"> | ||
<ng-container *ngIf="rowSelectionType === 'radio'"> | ||
<td | ||
[nzChecked]="setOfCheckedId.has(data.id)" | ||
[nzRowSelectionType]="'radio'" | ||
(nzCheckedChange)="onItemChecked(data.id, $event)" | ||
></td> | ||
</ng-container> | ||
|
||
<ng-container *ngIf="rowSelectionType === 'checkbox'"> | ||
<td [nzChecked]="setOfCheckedId.has(data.id)" (nzCheckedChange)="onItemChecked(data.id, $event)"></td> | ||
</ng-container> | ||
<td>{{ data.name }}</td> | ||
<td>{{ data.age }}</td> | ||
<td>{{ data.address }}</td> | ||
</tr> | ||
</tbody> | ||
</nz-table> | ||
`, | ||
styles: ` | ||
nz-radio-group { | ||
margin-block-end: 1rem; | ||
} | ||
` | ||
}) | ||
export class NzDemoTableSelectionComponent implements OnInit { | ||
rowSelectionType: NzRowSelectionType = 'checkbox'; | ||
|
||
checked = false; | ||
indeterminate = false; | ||
listOfCurrentPageData: readonly ItemData[] = []; | ||
listOfData: readonly ItemData[] = []; | ||
setOfCheckedId = new Set<number>(); | ||
|
||
updateCheckedSet(id: number, checked: boolean): void { | ||
if (checked) { | ||
if (this.rowSelectionType === 'radio') { | ||
this.setOfCheckedId.forEach(x => { | ||
this.setOfCheckedId.delete(x); | ||
}); | ||
} | ||
|
||
this.setOfCheckedId.add(id); | ||
} else { | ||
this.setOfCheckedId.delete(id); | ||
} | ||
} | ||
|
||
onItemChecked(id: number, checked: boolean): void { | ||
this.updateCheckedSet(id, checked); | ||
this.refreshCheckedStatus(); | ||
} | ||
|
||
onAllChecked(value: boolean): void { | ||
this.listOfCurrentPageData.forEach(item => this.updateCheckedSet(item.id, value)); | ||
this.refreshCheckedStatus(); | ||
} | ||
|
||
onCurrentPageDataChange($event: readonly ItemData[]): void { | ||
this.listOfCurrentPageData = $event; | ||
this.refreshCheckedStatus(); | ||
} | ||
|
||
refreshCheckedStatus(): void { | ||
this.checked = this.listOfCurrentPageData.every(item => this.setOfCheckedId.has(item.id)); | ||
this.indeterminate = this.listOfCurrentPageData.some(item => this.setOfCheckedId.has(item.id)) && !this.checked; | ||
} | ||
|
||
resetSelectedValues(): void { | ||
this.setOfCheckedId = new Set<number>(); | ||
this.indeterminate = false; | ||
} | ||
|
||
ngOnInit(): void { | ||
this.listOfData = new Array(5).fill(0).map((_, index) => ({ | ||
id: index, | ||
name: `Edward King ${index}`, | ||
age: 32, | ||
address: `London, Park Lane no. ${index}` | ||
})); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the order number 2 was unused.