首页 > 解决方案 > 完整的 ng-table (排序、搜索) not workink angular 10

问题描述

我正在尝试使用完整的 ng-table,但它不适用于 angular 10。

当我尝试复制粘贴代码时,此处出现错误

@Directive({
 selector: 'th[mzSortable]',
 host: {
 '[class.asc]': 'direction === "asc"',
 '[class.desc]': 'direction === "desc"',
 '(click)': 'rotate()'
 }
})

我试着用这个......

@Input() sortable: SortColumn = '';

@Input()
direction: SortDirection = '';

@Input()
@HostBinding('class.asc')
get ascClass (): any {
 return this.direction === 'asc';
}

@Input()
@HostBinding('class.desc')
get descClass (): any {
  return this.direction === 'desc';
}

@Output() sort = new EventEmitter<SortEvent>();

@HostListener('click')
rotate(): void {
  this.direction = rotate[this.direction];
  this.sort.emit({column: this.sortable, direction: this.direction});
}

现在表格出现了,但我无法对表格进行排序

标签: angularng-bootstrapngtableangular10

解决方案


我找到了,问题是我更改了指令前缀。替换了这个:

@Directive({
  selector: 'th[mzSortable]',
} 
})

这样:

@Directive({
  selector: 'th[sortable]',
} 
})

推荐阅读