Angular Material表格拖放列与排序不起作用
创始人
2024-10-19 21:30:15
0

要使Angular Material表格的拖放列和排序功能同时起作用,可以按照以下步骤进行操作:

首先,确保已经安装了正确版本的Angular Material和CDK。可以通过运行以下命令来安装它们:

npm install @angular/material @angular/cdk

接下来,在你的模块文件中导入所需的模块:

import { DragDropModule } from '@angular/cdk/drag-drop';
import { MatTableModule } from '@angular/material/table';

然后,在你的组件模板中,使用cdkDropList指令来启用拖放功能,并在mat-header-cellmat-cell元素上使用cdkDrag指令来启用拖动功能。例如:


    
Position {{element.position}}

最后,确保在组件类中定义了适当的数据源和要显示的列:

import { Component } from '@angular/core';

@Component({
  selector: 'app-table',
  templateUrl: './table.component.html',
  styleUrls: ['./table.component.css']
})
export class TableComponent {
  dataSource = [
    { position: 1, name: 'John' },
    { position: 2, name: 'Jane' },
    { position: 3, name: 'Mike' }
  ];

  displayedColumns = ['position', 'name'];
}

这样,你的Angular Material表格就同时具有拖放列和排序功能了。

希望以上解决方法对你有帮助!

相关内容

热门资讯

透视机巧!epoker底牌透视... 透视机巧!epoker底牌透视,cloudpoker怎么开挂(透视)都是存在有透视插件(哔哩哔哩)1...
透视练习!德普之星怎么设置埋牌... 透视练习!德普之星怎么设置埋牌,德普之星透视辅助软件(透视)确实有脚本方法(哔哩哔哩)1、让任何用户...
透视技法!wepoker怎么提... 透视技法!wepoker怎么提高运气,we poker辅助器下载(透视)竟然有脚本挂(哔哩哔哩)一、...
透视学习!hhpoker有没有... 透视学习!hhpoker有没有作必弊辅助,hh poker辅助器先试用(透视)竟然是有透视脚本(哔哩...
透视法子!德扑圈透视,德普之星... 透视法子!德扑圈透视,德普之星透视免费(透视)原来是真的透视工具(哔哩哔哩)1、德普之星透视免费公共...
透视经验!wepoker轻量版... 透视经验!wepoker轻量版透视方法,wepoker私人局规律(透视)一直是真的透视技巧(哔哩哔哩...
透视秘籍!wepoker免费辅... 透视秘籍!wepoker免费辅助器,wepoker怎么买辅助(透视)果然是真的脚本脚本(哔哩哔哩);...
透视学习!wepoker软件靠... 透视学习!wepoker软件靠谱么,wepoker透视有没有(透视)一直有透视脚本(哔哩哔哩)1、用...
透视绝活儿!德扑圈透视挂,德普... 透视绝活儿!德扑圈透视挂,德普之星私人局辅助免费(透视)竟然真的是有脚本工具(哔哩哔哩)1、德普之星...
透视教材!wepoker黑侠辅... 透视教材!wepoker黑侠辅助器,wepoker提高好牌率(透视)其实真的有透视神器(哔哩哔哩)1...