angular + ng-zorro 表格后台分页及排序功能实现,angular + ng-zorro 表格排序不起作用解决办法

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 = {
  // path: 'http://10.111.111.111:3000'

}

@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.bottomTable.pageNo = e
    this.outer.emit(e)
  }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Angular中,您可以使用ng-zorro-antd库中的`nz-date-picker`组件来创建一个带有日历和日期范围的日期选择器。以下是一个使用`nz-date-picker`的例子: 1. 首先,您需要在您的应用中安装和导入`ng-zorro-antd`库。 2. 在您的组件的HTML模板中添加一个`nz-date-picker`元素,并使用`nzMode`属性将其定义为日期选择器。 ```html <nz-date-picker nzMode="date"></nz-date-picker> ``` 3. 在您的组件中,您需要定义一个`nz-date-picker`对象,并将其与`nz-date-picker`元素相关联。您还可以使用`nzDisabledDate`属性来定义可选择的日期范围。 ```typescript import { Component } from '@angular/core'; import { NzDatePickerModule } from 'ng-zorro-antd/date-picker'; @Component({ selector: 'app-date-picker', templateUrl: './date-picker.component.html', styleUrls: ['./date-picker.component.css'] }) export class DatePickerComponent { disabledDate = (current: Date): boolean => { const minDate = new Date(2020, 0, 1); const maxDate = new Date(2020, 11, 31); return current < minDate || current > maxDate; } constructor() { } } ``` 在这个例子中,我们定义了一个`disabledDate`函数来禁用不在2020年1月1日和2020年12月31日之间的日期。 4. 最后,您需要在`nz-date-picker`中使用`nzFormat`属性来定义日期的格式。 ```html <nz-date-picker nzMode="date" nzFormat="yyyy-MM-dd" [nzDisabledDate]="disabledDate"></nz-date-picker> ``` 在这个例子中,我们将日期格式定义为`yyyy-MM-dd`。 这就是如何在Angular中使用ng-zorro-antd库中的`nz-date-picker`组件创建一个带有日历和日期范围的日期选择器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值