zoukankan      html  css  js  c++  java
  • (OK) Table component with sorting and pagination for Angular2


    https://www.npmjs.com/package/angular2-datatable


    Check live demo in plunker

    npm i -S angular2-datatable

    AppModule.ts

    import {NgModule} from "@angular/core";
    ...
    import {DataTableModule} from "angular2-datatable";
     
    @NgModule({
        imports: [
            ...
            DataTableModule
        ],
        ...
    })
    export class AppModule {
     
    }

    AppComponent.html

    <table class="table table-striped" [mfData]="data" #mf="mfDataTable" [mfRowsOnPage]="5">
        <thead>
        <tr>
            <th style=" 20%">
                <mfDefaultSorter by="name">Name</mfDefaultSorter>
            </th>
            <th style=" 50%">
                <mfDefaultSorter by="email">Email</mfDefaultSorter>
            </th>
            <th style=" 10%">
                <mfDefaultSorter by="age">Age</mfDefaultSorter>
            </th>
            <th style=" 20%">
                <mfDefaultSorter by="city">City</mfDefaultSorter>
            </th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let item of mf.data">
            <td>{{item.name}}</td>
            <td>{{item.email}}</td>
            <td class="text-right">{{item.age}}</td>
            <td>{{item.city | uppercase}}</td>
        </tr>
        </tbody>
        <tfoot>
        <tr>
            <td colspan="4">
                <mfBootstrapPaginator [rowsOnPageSet]="[5,10,25]"></mfBootstrapPaginator>
            </td>
        </tr>
        </tfoot>
    </table>
    • selector: table[mfData]
    • exportAs: mfDataTable
    • inputs
      • mfData: any[] - array of data to display on table
      • mfRowsOnPage: number - number of rows should be displayed on page (default: 1000)
      • mfActivePage: number - page number should be displayed on init (default: 1)
    • selector: mfDefaultSorter
    • inputs
      • by: any - specify how to sort data (argument for lodash function _.sortBy )

    Displays buttons for changing current page and number of displayed rows using bootstrap template (css for bootstrap is required). If array length is smaller than current displayed rows on page then it doesn't show button for changing page. If array length is smaller than min value rowsOnPage then it doesn't show any buttons.

    • selector: mfBootstrapPaginator
    • inputs
      • rowsOnPageSet: number - specify values for buttons to change number of diplayed rows

  • 相关阅读:
    vue2查看大图vue-preview使用笔记
    promise使用场景
    vue2移动端使用vee-validate进行表单验证
    移动端单位换算理解
    ...
    我的promise学习笔记
    前端本地调试解决跨域的两种方法
    vue2 零星笔记
    vue2.x使用百度地图
    BZOJ 3368 约翰看山(扫描)O(N)
  • 原文地址:https://www.cnblogs.com/ztguang/p/12645254.html
Copyright © 2011-2022 走看看