angular + ng-zorro 表格排序不起作用是因为数据是从后端获取的,也是后端分页,所以要自己写排序啦~~~~
举例:HTML
<nz-table #basicTable nzBordered [nzData]="listOfData" [nzTotal]="bottomTable.total"
[nzPageSize]="bottomTable.pageSize" [nzFrontPagination]="false" [nzPageIndex]="bottomTable.pageNo"
[nzScroll]="{ x: '1340px', y: '230px' }" class="bottom_table" (nzPageIndexChange)="myChange($event)">
<thead>
<tr>
<th nzWidth="180px">A</th>
<th nzWidth="100px">B</th>
<th nzWidth="100px">C</th>
<th nzWidth="100px">D</th>
<th nzWidth="100px">E</th>
<th nzWidth="100px">F</th>
<th nzWidth="250px"
[nzSortFn]="true"
(nzSortOrderChange)="sortChange($event)"
>G</th>
<th nzWidth="100px">H</th>
<th nzWidth="100px">I</th>
<th nzWidth="110px">J</th>
<th nzWidth="100px"
[nzSortFn]="true"
(nzSortOrderChange)="sortChange1($event)"
>K</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of basicTable.data" (click)="openAnalysis(data)" class="my_small_tr">
<td>{{ data.a }}</td>
<td>{{ data.b }}</td>
<td>{{ data.c }}</td>
<td>{{ data.d }}</td>
<td>{{ data.e }}</td>
<td>{{ data.f }}</td>
<td>{{ data.g }}</td>
<td>{{ data.h }}</td>
<td>{{ data.i }}</td>
<td>{{ data.j }}</td>
<td>{{ data.k }}</td>
</tr>
</tbody>
</nz-table>
TS文件
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { I18NService } from '@core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { myCommonService } from 'src/app/core/net/hr_report/myCommon.service';
import { CommonFunService } from 'src/app/core/net/common_zz/common-fun.service';
import { TossAnalysisComponent } from '../../analysis/analysis.component';
import { NzTableFilterFn, NzTableFilterList, NzTableSortFn, NzTableSortOrder } from 'ng-zorro-antd/table';
const BaseUrl = {
}
@Component({
selector: 'app-report',
templateUrl: './report.component.html',
styleUrls: ['./report.component.less']
})
export class ReportComponent implements OnInit {
@Input()
public listOfData: any = []
@Input()
public form: any = {}
@Output()
private outer: EventEmitter<any> = new EventEmitter();
@Input()
public record: string = ''
@Input()
public bottomTable: any = {}
constructor(
public msg: NzMessageService,
public mlbCom: myCommonService,
public I18NService: I18NService,
public http: _HttpClient,
public commonFun: CommonFunService,
private modal: ModalHelper,
) { }
ngOnInit(): void {
}
sortChange(e) {
console.log(e)
this.listOfData = e === 'ascend' ? this.listOfData.sort(
(a, b) => a.stationId.localeCompare(b.stationId)
) : this.listOfData.sort(
(a, b) => b.stationId.localeCompare(a.stationId)
)
}
sortChange1(e) {
console.log(e)
this.listOfData = e === 'ascend' ? this.listOfData.sort(
(a, b) => a.tossRate - b.tossRate
) : this.listOfData.sort(
(a, b) => b.tossRate - a.tossRate
)
}
myChange(e) {
this.outer.emit(e)
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决