angularjs - 如何向 ngx-bootstrap 分页添加过滤器?

标签 angularjs pagination ngx-bootstrap ngx-pagination

这段代码是关于 ngx-bootstrap 分页的。我想要搜索项目。

<table class="table  transactionhistory_table" id="myTable">
    <thead>
        <tr class="transactionhistory_table_tr">
            <th>REFERENCE ID</th>
            <th>RECHARGE AMOUNT</th>
            <th>TOTAL AMOUNT</th>
            <th>BOOKING TYPE</th>
            <th>TRANSACTION TYPE</th>
            <th>DATE</th>
            <th>STATUS</th>
        </tr>
    </thead>
    <tbody id="operatorName"*ngFor="let data of returnedArray | filter:filter">
       <tr>
          <td class="transactionhistory_table_tr_td">{{data.transactionId}}</td>
          <td class="transactionhistory_table_tr_td">{{data.rechargeAmount}}</td>
          <td class="transactionhistory_table_tr_td">{{data.walletAmount}}</td>
          <td class="transactionhistory_table_tr_td">{{data.bookingType}}</td>
          <td class="transactionhistory_table_tr_td">{{data.transactionType}</td>
          <td class="transactionhistory_table_tr_td">{{data.createdDate}}</td>
          <td class="transactionhistory_table_tr_td">{{data.transactionStatus}}</td>
       </tr>    
</tbody>
</table> 

 </div>
        <div class="col-xs-12 col-12 no-padding">
        <span class="pagination_class">
<p class="page_no">({{startVal}}-{{endVal}} of {{walletTransactionsCount}})</p>
        <div class="pagination_class">
    <!-- <pagination-controls   previousText="&lsaquo;" nextText="&rsaquo;" (pageChanged)="pageChanged(p=$event)"></pagination-controls>  -->
        <pagination [boundaryLinks]="true" [totalItems]="walletTransactionsCount"   previousText="&lsaquo;" nextText="&rsaquo;" firstText="&laquo;" lastText="&raquo;" (itemsPerPage)="3" (pageChanged)="pageChanged($event)" [maxSize]="5"></pagination>
        </div> 
    </span> 
</div>

我想用分页过滤表格我使用了 ng2searchpipe 模块,但它只过滤一个 TR 而不是所有数据。

pageChanged(event: PageChangedEvent): void {
        event.itemsPerPage = 3;
        const startItem = (event.page - 1) * event.itemsPerPage;
        const endItem = event.page * event.itemsPerPage;
        this.startVal = startItem + 1;
        this.endVal = endItem;
        this.returnedArray = this.walletTransaction.slice(startItem, endItem);
}

最佳答案

我使用了不同的方法来实现这一点。我没有使用传统的过滤器管道,而是在搜索模型更改时实现了过滤器方法,以从原始数组中过滤出数据并存储在 contentArray 中。然后我调用了 pageChange 方法来影响数据的分页。我的代码如下:

HTML:

<input type="text" placeholder="Search" [(ngModel)]="filterSearchData" (ngModelChange)="changeSearchFilter($event)" />

组件网:

changeSearchFilter(filterText: string) {
    this.contentArray= this.rawDataList.filter((dataItem: any) =>
        dataItem.guestName.toLowerCase().includes(filterText.toLowerCase())
    );

    this.pageChanged({
        page: 1,
        itemsPerPage: this.pageItems
    });
    this.cd.detectChanges();
}

pageChanged(event: PageChangedEvent): void {
    const startItem = (event.page - 1) * event.itemsPerPage;
    const endItem = event.page * event.itemsPerPage;
    this.returnedArray = this.contentArray.slice(startItem, endItem);
  }

关于angularjs - 如何向 ngx-bootstrap 分页添加过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50565430/

相关文章:

angular - 如何在表单内的 Angular ngx-bootstrap 的日期选择器中更改日期格式

javascript - AngularJS Controller 缓存在 Firefox 和 IE : how to disable?

javascript - 我如何正确地在分页表中附加 div

javascript - AngularJS 指令 - 插值时出错

node.js - 安装 ngx-admin 的库时 npm install 过程中出现问题

javascript - ngx-bootstrap 选项卡在通过传单打开的模式中不起作用

javascript - 基于JSON属性的Angular img切换

php - 创建一个高效的分页系统

javascript - 更改上一页和下一页以进行分页,具有过滤功能

JQuery,分层表分页