角度6数据表活动页

时间:2018-10-09 09:24:34

标签: angular angular6 angular-datatables npmjs

你好,角社区,

我对“ angular-6-datatable”包有问题,除活动页面外,其他一切正常。

这是我的组件代码:

import {AfterViewInit, Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {BrService} from '../../services/br.service';
import {AuthService} from '../../services/auth.service';
import {ActivatedRoute, Router} from '@angular/router';
import {ToastaConfig, ToastaService, ToastOptions} from 'ngx-toasta';
import {DataTable} from 'angular-6-datatable';


@Component({
  selector: 'app-br-table',
  templateUrl: './br-table.component.html',
  styleUrls: ['./br-table.component.scss']
})
export class BrTableComponent implements OnInit, OnDestroy, AfterViewInit {

  static searchBy = 'name';
  static searchInput: string;
  static activePage = 2;
  static rowsOnPage = 5;

  brs: any[];
  brSubscription: Subscription;
  activePage = 10;
  rowsOnPage = 5;
  mfDataTable;

  constructor(private brService: BrService,
              private authService: AuthService,
              private toastaService: ToastaService,
              private toastaConfig: ToastaConfig,
              private router: Router,
              private route: ActivatedRoute) {
    // Assign the selected theme name to the `theme` property of the instance of ToastaConfig.
    // Possible values: default, bootstrap, material
    this.toastaConfig.theme = 'bootstrap';
  }


  ngAfterViewInit(): void {
    const msg: string = this.route.snapshot.queryParamMap.get('msg');
    const type: string = this.route.snapshot.queryParamMap.get('type');
    if (msg != null) {
      this.addToast(msg, type);
    }
  }

  ngOnInit() {
    this.subscribeOnBrs();
    this.filterBrs();
  }

  subscribeOnBrs() {
    this.brSubscription = this.brService.brsSubject.subscribe(
      (brs: any[]) => {
        this.brs = brs;
        this.rowsOnPage = BrTableComponent.rowsOnPage;
        this.activePage = BrTableComponent.activePage;
        console.log('mf:');
        console.log(this.mfDataTable);
      }
    );
    this.brService.emitBrSubject();
  }

  onPaginatorClick(mf: HTMLTableElement) {
    console.log('onPaginatorClick...');
    console.log(mf);
    this.mfDataTable = mf;
    BrTableComponent.activePage = mf.activePage;
    BrTableComponent.rowsOnPage = mf.rowsOnPage
  }
 }
<table class="table table-striped table-hover table-sm table-responsive-md"
       [mfData]="brs" #mf="mfDataTable"
       [mfRowsOnPage]="rowsOnPage"
       [mfActivePage]="activePage"
>
  <thead>
  <tr>
    <th scope="col">
      <mfDefaultSorter by="name">Nom</mfDefaultSorter>
    </th>
    <th scope="col">
      <mfDefaultSorter by="version">Version</mfDefaultSorter>
    </th>
    <th scope="col">
      <mfDefaultSorter by="Type">Type</mfDefaultSorter>
    </th>
    <th scope="col">
      <mfDefaultSorter by="status">Statut</mfDefaultSorter>
    </th>
    <th scope="col">
      <mfDefaultSorter by="author">Auteur</mfDefaultSorter>
    </th>
    <th scope="col">
      <mfDefaultSorter by="jira">Jira</mfDefaultSorter>
    </th>
  </tr>
  </thead>
  <tbody>
  <tr class="tr-hover" *ngFor="let item of mf.data" (click)="onClickRow(item.pk)">
    <th scope="row">{{item.name}}</th>
    <td>{{item.version}}</td>
    <td>{{item.Type}}</td>
    <td>{{item.status | uppercase}}</td>
    <td>{{item.author | uppercase}}</td>
    <td>{{item.jira}}</td>
  </tr>
  </tbody>
  <tfoot>
  <tr>
    <td colspan="6">
      <mfBootstrapPaginator [rowsOnPageSet]="[5,10,25]" (click)="onPaginatorClick(mf)"></mfBootstrapPaginator>
    </td>
  </tr>
  </tfoot>
</table>

使用此代码,我可以保留用户选择的行号,但是我不知道为什么,它对活动页面不起作用。

我已经阅读了官方文档:https://www.npmjs.com/package/angular-6-datatable,但看不到我做错了什么。

请帮助我

0 个答案:

没有答案