Skip to content

Commit

Permalink
fix(module:table): fix table no data colSpan (#5533)
Browse files Browse the repository at this point in the history
close #5509
close #5481
  • Loading branch information
vthinkxie authored Jul 9, 2020
1 parent 13875cb commit 7f133af
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions components/table/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ Checkbox property
| `[nzIndeterminate]` | Indeterminate status | `boolean` | - |
| `[nzChecked]` | Checked status, double binding | `boolean` | - |
| `(nzCheckedChange)` | Checked status change callback | `EventEmitter<boolean>` | - |
| `[colspan]` | how many columns the cell extends | `number` | `null` |
| `[rowspan]` | how many rows the cell extends | `number` | `null` |
| `[colSpan]` | how many columns the cell extends | `number` | `null` |
| `[rowSpan]` | how many rows the cell extends | `number` | `null` |

Expand property

Expand Down
4 changes: 2 additions & 2 deletions components/table/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ Table 组件同时具备了易用性和高度可定制性
| `[nzAlign]` | 设置列内容的对齐方式 | `'left' \| 'right' \| 'center'` | - |
| `[nzBreakWord]` | 是否折行显示 | `boolean` | `false` |
| `[nzEllipsis]` | 超过宽度将自动省略,暂不支持和排序筛选一起使用。仅当表格布局将为 `nzTableLayout="fixed"`时可用 | `boolean` | `false` |
| `[colspan]` | 每单元格中扩展列的数量 | `number` | `null` |
| `[rowspan]` | 每单元格中扩展行的数量 | `number` | `null` |
| `[colSpan]` | 每单元格中扩展列的数量 | `number` | `null` |
| `[rowSpan]` | 每单元格中扩展行的数量 | `number` | `null` |


其他
Expand Down
1 change: 1 addition & 0 deletions components/table/src/cell/cell-fixed.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class NzCellFixedDirective implements OnChanges {
@Input() nzRight: string | boolean = false;
@Input() nzLeft: string | boolean = false;
@Input() colspan: number | null = null;
@Input() colSpan: number | null = null;
changes$ = new Subject<void>();
isAutoLeft = false;
isAutoRight = false;
Expand Down
18 changes: 11 additions & 7 deletions components/table/src/cell/th-measure.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ export class NzThMeasureDirective implements OnChanges {
changes$ = new Subject();
@Input() nzWidth: string | null = null;
@Input() colspan: string | number | null = null;
@Input() colSpan: string | number | null = null;
@Input() rowspan: string | number | null = null;
@Input() rowSpan: string | number | null = null;
constructor(private renderer: Renderer2, private elementRef: ElementRef) {}
ngOnChanges(changes: SimpleChanges): void {
const { nzWidth, colspan, rowspan } = changes;
if (colspan) {
if (!isNil(this.colspan)) {
this.renderer.setAttribute(this.elementRef.nativeElement, 'colspan', `${this.colspan}`);
const { nzWidth, colspan, rowspan, colSpan, rowSpan } = changes;
if (colspan || colSpan) {
const col = this.colspan || this.colSpan;
if (!isNil(col)) {
this.renderer.setAttribute(this.elementRef.nativeElement, 'colspan', `${col}`);
} else {
this.renderer.removeAttribute(this.elementRef.nativeElement, 'colspan');
}
}
if (rowspan) {
if (!isNil(this.rowspan)) {
this.renderer.setAttribute(this.elementRef.nativeElement, 'rowspan', `${this.rowspan}`);
if (rowspan || rowSpan) {
const row = this.rowspan || this.rowSpan;
if (!isNil(row)) {
this.renderer.setAttribute(this.elementRef.nativeElement, 'rowspan', `${row}`);
} else {
this.renderer.removeAttribute(this.elementRef.nativeElement, 'rowspan');
}
Expand Down
4 changes: 2 additions & 2 deletions components/table/src/table-style.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class NzTableStyleService {
setListOfTh(listOfTh: NzThMeasureDirective[]): void {
let columnCount = 0;
listOfTh.forEach(th => {
columnCount += (th.colspan && +th.colspan) || 1;
columnCount += (th.colspan && +th.colspan) || (th.colSpan && +th.colSpan) || 1;
});
const listOfThPx = listOfTh.map(item => item.nzWidth);
this.columnCount$.next(columnCount);
Expand All @@ -77,7 +77,7 @@ export class NzTableStyleService {
setListOfMeasureColumn(listOfTh: NzThMeasureDirective[]): void {
const listOfKeys: string[] = [];
listOfTh.forEach(th => {
const length = (th.colspan && +th.colspan) || 1;
const length = (th.colspan && +th.colspan) || (th.colSpan && +th.colSpan) || 1;
for (let i = 0; i < length; i++) {
listOfKeys.push(`measure_key_${i}`);
}
Expand Down
6 changes: 2 additions & 4 deletions components/table/src/table/thead.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class NzTheadComponent implements AfterContentInit, OnDestroy, AfterViewI
private destroy$ = new Subject<void>();
isInsideTable = false;
@ViewChild('contentTemplate', { static: true }) templateRef!: TemplateRef<NzSafeAny>;
@ContentChildren(NzTrDirective) listOfNzTrDirective!: QueryList<NzTrDirective>;
@ContentChildren(NzTrDirective, { descendants: true }) listOfNzTrDirective!: QueryList<NzTrDirective>;
@ContentChildren(NzThAddOnComponent, { descendants: true }) listOfNzThAddOnComponent!: QueryList<NzThAddOnComponent>;
/** @deprecated use nzSortFn and nzSortPriority instead **/
@Input() @InputBoolean() nzSingleSort = false;
Expand All @@ -80,9 +80,7 @@ export class NzTheadComponent implements AfterContentInit, OnDestroy, AfterViewI
ngOnChanges(changes: SimpleChanges): void {
const { nzSingleSort } = changes;
if (nzSingleSort) {
warnDeprecation(
`'nzSingleSort' is deprecated and will be removed in 10.0.0. Please use 'nzSortFn' and 'nzSortPriority' instead.`
);
warnDeprecation(`'nzSingleSort' is deprecated and will be removed in 10.0.0. Please use 'nzSortFn' and 'nzSortPriority' instead.`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/table/src/table/tr.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class NzTrDirective implements AfterContentInit, OnDestroy {
listOfLeftCell.forEach((cell, index) => {
if (cell.isAutoLeft) {
const currentArray = listOfLeftCell.slice(0, index);
const count = currentArray.reduce((pre, cur) => pre + (cur.colspan || 1), 0);
const count = currentArray.reduce((pre, cur) => pre + (cur.colspan || cur.colSpan || 1), 0);
const width = listOfAutoWidth.slice(0, count).reduce((pre, cur) => pre + cur, 0);
cell.setAutoLeftWidth(`${width}px`);
}
Expand All @@ -76,7 +76,7 @@ export class NzTrDirective implements AfterContentInit, OnDestroy {
const cell = listOfRightCell[listOfRightCell.length - index - 1];
if (cell.isAutoRight) {
const currentArray = listOfRightCell.slice(listOfRightCell.length - index, listOfRightCell.length);
const count = currentArray.reduce((pre, cur) => pre + (cur.colspan || 1), 0);
const count = currentArray.reduce((pre, cur) => pre + (cur.colspan || cur.colSpan || 1), 0);
const width = listOfAutoWidth
.slice(listOfAutoWidth.length - count, listOfAutoWidth.length)
.reduce((pre, cur) => pre + cur, 0);
Expand Down

0 comments on commit 7f133af

Please sign in to comment.