brunano21 / angular-4-data-table

An Angular 5 data table, with pagination, sorting, expandable rows, row selection, etc. with basic accessibility support.
MIT License
11 stars 19 forks source link

Angular 5 DataTable

Note: Originally this was fork of this package.

A simple Angular 5 data table, with built-in solutions for features including:

The component can be used not just with local data, but remote resources too, ie. when sorting and/or pagination are implemented server side.

The library is packaged with ng-packagr.

Dependencies

Furthermore the component is based on Bootstrap v4.0 (CSS-only) and Font-Awesome v4.7, hence be sure to include them into your project. Most likely you need to install them as dependencies...

npm install bootstrap@4.0.0 font-awesome@4.7.0

... then you need to include the CSS bundles into .angular-cli.json file as show below.

{
  "apps": [
    {
      "root": "src",
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/font-awesome/css/font-awesome.css",
        "styles.css"
      ]
    }
 ]
}

Installation

npm install angular5-data-table

Usage

1.Import Datatable module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { DataTableModule } from 'angular5-data-table';

@NgModule({
  imports: [
  ...
  DataTableModule.forRoot()
  ...
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
2. Include <data-table> and <data-table-column> into your component's template.
<!-- my.component.template -->
<div>
...
 <data-table id="my-table"
  ...
  [title]="'Employees'"
  [items]="items"
  [itemCount]="itemCount"
  ...
  >
  <data-table-column
    [property]="'name'"
    [header]="'name'"
    ... >
  </data-table-column>
  <data-table-column
    ...
  </data-table-column>
</data-table>
...
</div>

API

data-table

data-table-column

Custom column templates

data-column's content and header are not restricted to be text only - they can hold complex content too. In order to do that developers can use two references: #dataTableHeader and #dataTableCell.

Usage and sample

</data-table>
  ...
  <data-table-column
    header="Actions">
    <ng-template #dataTableHeader let-item="item">
      <i>Actions</i>
    </ng-template>
    <ng-template #dataTableCell let-item="item">
      <button (click)="carClicked(item)" class="btn btn-sm btn-default">Buy</button>
    </ng-template>
  </data-table-column>
  ...
</data-table>

As it can be seen from the above snippet, the dataTableHeader and dataTableCell are targeting two <ng-template>s nodes which will be used respectively as column header and cell content. In both cases item refers to the whole row item, so developers can use whatever they may need.

Demo app

Clone this repository, run npm install and ng serve, then navigate to http:localhost:4200 where you can access to the demo application sporting a few demos with code viewer and docs.

Examples

Demo1 Demo2 Demo3 Demo4 Demo5

License

MIT License