Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

angular2-datatable-m

saravanancomsc11MIT1.0.0TypeScript support: included

DataTable component for Angular2 framework

angular, angularjs, angular2, ng, ng2, table, pagination, sort, sorting

readme

Table component with sorting and pagination for Angular2

npm version Build Status Code Climate Test Coverage npm downloads

Demo

Check live demo in plunker

Installation

npm i -S angular2-datatable

Usage example

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="width: 20%">
            <mfDefaultSorter by="name">Name</mfDefaultSorter>
        </th>
        <th style="width: 50%">
            <mfDefaultSorter by="email">Email</mfDefaultSorter>
        </th>
        <th style="width: 10%">
            <mfDefaultSorter by="age">Age</mfDefaultSorter>
        </th>
        <th style="width: 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>

API

mfData directive

  • selector: table[mfData]
  • exportAs: mfDataTable
  • inputs
    • mfData: any[] - array of data to display in table
    • mfRowsOnPage: number - number of rows should be displayed on page (default: 1000)
    • mfActivePage: number - page number (default: 1)
    • mfSortBy: any - sort by parameter
    • mfSortOrder: string - sort order parameter, "asc" or "desc"
  • outputs
    • mfSortByChange: any - sort by parameter
    • mfSortOrderChange: any - sort order parameter

mfDefaultSorter component

  • selector: mfDefaultSorter
  • inputs
    • by: any - specify how to sort data (argument for lodash function _.sortBy )

mfBootstrapPaginator component

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

changelog

Changelog

0.6.0 (2017-03-27)

Fixes:

- fix AOT incompatibility, changing @angular dependencies to peerDependencies, thanks to @trevex (#91)

0.5.2 (2016-11-13)

Changes:

- added inputs/outputs for sorting (#14)

Bugfixes:

- detect changes in inputData array (#10)
- fixed detecting changes in mfRowsOnPage (#32)
- fixed support for AOT compilation

0.5.1 (2016-10-25)

Changes:

- changed the old "typings" system to the new "@types" system
- added support for AOT compilation

Bugfixes:

- sorting by child properties (#41)

0.5.0 (2016-10-09)

Breaking changes:

- update angular library to 2.0.0

Bugfixes:

- sort case insensitive
- fixed pagination, fix #29, #33

Changelog

0.4.2 (2016-05-11)

Breaking changes:

- update angular library to 2.0.0-rc.0

0.3.0 (2016-05-08)

Breaking changes:

- move `rowsOnPage` and `activePage` input from BootstrapPaginator to DataTable directive

Bugfixes:

- fix error when mfData input is undefined
- add src so map files should have correct paths

0.2.5 (2016-04-19)

Bugfixes:

- fix not visible paginator

0.2.4 (2016-04-19)

Bugfixes:

- add import for lodash in file `DataTable.ts`

0.2.3 (2016-03-21)

Bugfixes:

- remove `href` attribute from DefaultSorter
- add style `cursor: pointer` to links in DefaultSorter and BootstrapPaginator

0.2.2 (2016-03-21)

Bugfixes:

- remove `href` attribute from BootstrapPaginator template