Angular11-ng-modal表格中的mat-sort无法正常工作
创始人
2024-10-21 16:00:49
0

在使用mat-sort进行表格排序时,需要在要排序的列上添加mat-sort-header属性,并将所需的排序依据指定为mat-sort-header的值。 在ng-modal中使用mat-sort时,需要在ng-modal所在组件中导入MatTableModule和MatSortModule模块,并在ngOnInit函数中初始化MatSort实例,并将其赋值给matSort属性。然后,在模板文件中,将matSort属性绑定到mat-table的matSort属性上,以激活mat-sort。 以下是一个示例代码: component.ts:

import { Component, OnInit, ViewChild } from '@angular/core';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';

@Component({
  selector: 'app-table',
  templateUrl: './table.component.html',
  styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {
  @ViewChild(MatSort) sort: MatSort;

  displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
  dataSource = new MatTableDataSource(ELEMENT_DATA);

  ngOnInit() {
    this.dataSource.sort = this.sort;
  }
}

export interface Element {
  name: string;
  position: number;
  weight: number;
  symbol: string;
}

const ELEMENT_DATA: Element[] = [
  {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
  {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
  {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
  {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
  {position: 5, name: 'Boron', weight: 10.81, symbol: 'B'},
  {position: 6, name: 'Carbon', weight: 12.011, symbol: 'C'},
  {position: 7, name: 'Nitrogen', weight: 14.007, symbol

相关内容

热门资讯

日前!蛮籽麻旺重庆辅助&quo... 日前!蛮籽麻旺重庆辅助"本来是真的有辅助攻略"(哔哩哔哩)1、不需要AI权限,帮助你快速的进行蛮籽麻...
这一问题亟待解决!中至赣牌圈祈... 这一问题亟待解决!中至赣牌圈祈福转运"一直真的有辅助工具"(哔哩哔哩)这一问题亟待解决!中至赣牌圈祈...
最终!新道游正版辅助"... 您好,新道游正版辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家...
明白辅助挂!新道游正版开挂&q... 明白辅助挂!新道游正版开挂"竟然是真的有辅助神器"(哔哩哔哩)在进入新道游正版开挂软件靠谱后,参与本...
教学辅助挂!神途免费辅助软件&... 教学辅助挂!神途免费辅助软件"原来真的有辅助器"(哔哩哔哩)1、神途免费辅助软件辅助软件下载优化,神...
近期!熊猫免费脚本辅助工具&q... 近期!熊猫免费脚本辅助工具"一贯真的有辅助脚本"(哔哩哔哩)1.熊猫免费脚本辅助工具 选牌创建新账号...
2026版辅助挂!打两圈怀疑有... 2026版辅助挂!打两圈怀疑有外g挂"竟然真的有辅助软件"(哔哩哔哩)1、完成打两圈怀疑有外g挂辅助...
2026版技巧!蜀山四川智能辅... 2026版技巧!蜀山四川智能辅助插件"一贯真的有辅助工具"(哔哩哔哩)一、蜀山四川智能辅助插件游戏安...
黑科技攻略!广西老友玩插件&q... 黑科技攻略!广西老友玩插件"本来是有辅助插件"(哔哩哔哩)1、每一步都需要思考,不同水平的挑战广西老...
此事引发广泛关注!多乐跑得快私... 此事引发广泛关注!多乐跑得快私人房间作必弊视频"确实存在有辅助脚本"(哔哩哔哩)1、多乐跑得快私人房...