0.0.17 • Published 4 years ago

ng-bootstrap-table v0.0.17

Weekly downloads
29
License
Apache-2.0
Repository
github
Last release
4 years ago

Travis (.com) npm npm GitHub stars GitHub forks

ng-bootstrap-table (WIP)

new_paginator

A lightweight, bootstrap styled Angular data table component!

Prerequisites:

Make sure that you have already installed bootstrap! If you do not, you can add it by CDN. Just add a link tag into your index.html like the link below:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

Otherwise, you can add it via NPM simple by running the following command:

npm install --save bootstrap

Then you have to link the bootstrap.min.css into you styles in your angular.json file.

 "styles": [
              ...
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              ...
            ]

Installation:

Install the ng-bootstrap-table package via NPM using the command below:

npm i ng-bootstrap-table

Importing the BootstrapTableModule

import { BootstrapTableModule } from 'ng-bootstrap-table';

@NgModule({
  ...
   imports: [
      ...,
      BootstrapTableModule 
   ],
   ...
})
export class AppModule { }

Usage examples

Dynamic rows and columns

<b-table [columns]="columns" [value]="data" [striped]="true" [bordered]="true" [small]="true" (onRowUnselect)="selectedRow=$event">
    <ng-template bTemplate="header">
      <tr>
        <th *ngFor="let col of columns">{{col.header}}</th>
      </tr>
    </ng-template>
    <ng-template bTemplate="body" let-rowData>
      <tr [bSelectableRow]="rowData" [ngClass]="{'table-active':selectedRow?.selected && selectedRow?.data===rowData}">
        <td *ngFor="let col of columns">{{rowData[col.field]}}</td>
      </tr>
    </ng-template>
  </b-table>

Column definition

  columns:BTableColumn[]=[
    {header:'Name',field:'name'},
    {header:'Username',field:'username'},
    {header:'Email',field:'email'},
    {header:'Phone',field:'phone'},
    {header:'Website',field:'website'}
  ];

Paginator configuration

Alternatively, you can configure the paginator by providing a PaginatorConfig object in the paginatorConfig attribute of b-table. With this you will be abple to adjust to paginator sizing and alignment.

export class PaginatorConfig {
    sizing: Sizing;
    alignment: Alignment = Alignment.RIGHT;
}

For example:

    this.pConfig= new PaginatorConfig();
    this.pConfig.sizing = Sizing.SMALL;
    this.pConfig.alignment= Alignment.CENTER;

After that, you have to enable paginator into b-table component like below.

<b-table *ngIf="data" [columns]="columns" [value]="data" [striped]="true" [bordered]="true" [small]="true"
    [paginator]="true" [paginatorConfig]="pConfig" [rows]="rows" [totalRecords]="_data?.length" [hover]="true"
    (onRowSelect)="selectedRow=$event;onRowSelect($event)" (onRowUnselect)="selectedRow=$event;onRowUnselect($event)"
    (onPageChange)="onPageChange($event)">
    <ng-template bTemplate="header">
      <tr>
        <th *ngFor="let col of columns">{{col.header}}</th>
      </tr>
    </ng-template>
    <ng-template bTemplate="body" let-rowData>
      <tr [bSelectableRow]="rowData" [ngClass]="{'table-active':selectedRow?.selected && selectedRow?.data===rowData}">
        <td *ngFor="let col of columns">{{rowData[col.field]}}</td>
      </tr>
    </ng-template>
  </b-table>

Documentation

List of all supported properties which must/can be used with b-table.

PropertyTypeDefaultShort Description
columnsBTableColumn arraynullAn array of objects to represent dynamic columns.
valuearraynullAn array of objects to display.
paginatorbooleanfalseDefines if the table should be have a paginator or not.
paginatorConfigPaginatorConfigAlignment.RIGHTProvides configuration for the paginator.
rowsnumbernullDefines the total number of rows per page in the table.
totalRecordsnumbernullThe total number of value entries.
stripedbooleannullMakes table striped by adding the .table-striped class.
borderedbooleannullMakes table bordered by adding the .table-bordered class.
borderlessbooleannullMakes table borderless by adding the .table-borderless class.
smallbooleannullMakes table small by adding the .table-sm class.
darkbooleannullMakes table dark by adding the .table-dark class.
hoverbooleannullMakes table hoverable by adding the .table-hover class.
headLightbooleannullMakes table head light by adding the .thead-light class.
headDarkbooleannullMakes table head dark by adding the .thead-dark class.
responsivebooleanfalseMakes table responsive by adding the .table-responsive class.

List of events

EventParametersDescription
onRowSelectBRowEventCallback to be invoked when a row is selected.
onRowUnselectBRowEventCallback to be invoked when a row was unselected.
onPageChangePageEventCallback to be invoked when a page is changed.

PageEvent event format

onPageChange: Returns a PageEvent with the following stracture.

{
  nextPage: 3,
  activePage: 2,
  previousPage: 1,
  rowsPerPage: 4,
  totalRecords: 10
  totalPages: 3,
  limit: 4,
  offset: 4
}

BRowEvent event format

{
    originalEvent:any,
    data:any,
    selected:boolean
}

Contribution

Feel free to contribute and/or report a bug at the GitHub Repository.

License

ng-bootstrap-table is released under the Apache license.

0.0.10

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.1.0

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago