1.0.1 • Published 6 years ago

es-ng-bs-table v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

ES Angular bootstrap Table

Features

  • create for bootstrap 4
  • card view in mobile
  • get json data from server
  • flexible header and cell template
  • support client and server pagination
  • keep search result on url
  • easy to extend tool

Table of contents

Setup

First you need to install the npm module

npm install es-ng-bs-table

Then import bootstrap 4 css in .angular-cli.json

{
  "apps": {
     "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.css",
        "../node_modules/open-iconic/font/css/open-iconic-bootstrap.css"
     ]
  }
}

Last import the 'HttpClientModule' and 'BsTableModule' to module

import {NgModule} from "@angular/core"
import {HttpClientModule} from "@angular/common/http";
import {BsTableModule} from "es-ng-bs-table";

@NgModule{
    imports: [
        HttpClientModule,
        BsTableModule,
        //if you want to keep search result
        //RouterModule
    ],
    /* if you want to add some http interceptors
    providers: [
        {provide: HTTP_INTERCEPTORS ...}
    ]
    */
}
export class AppModule{}

Usage

client side pagination

<es-ng-table></es-ng-table>

client side pagination structure

Array<any>

server side pagination

<es-ng-sd-table></es-ng-sd-table>

server side pagination structure

{
    rows: Array<any>;
    total: number;
}

server side params

{
    limit: number;
    offset: number;
    sort: string;
    order: string;
    search: string;
    query: string; //json
}

Basic Usage

ts:

export class AppComponent {
  data = [
    {id: 1, name: "Sean Johnston", score: 99, description: "d1"},
    {id: 2, name: "Morgan Davies", score: 80, description: "d2"},
    {id: 3, name: "Morgan John", score: 80, description: "d3"},
    {id: 4, name: "Tommy Walker", score: 80, description: "d4"},
    {id: 5, name: "William Lee", score: 80, description: "d5"},
    {id: 6, name: "Russell Brady", score: 80, description: "d6"},
    {id: 7, name: "Isaiah Ferguson", score: 80, description: "d7"},
    {id: 8, name: "Dominic Lynch", score: 80, description: "d8"},
    {id: 9, name: "Alberto Walls", score: 80, description: "d9"},
    {id: 10, name: "Jerry Pate", score: 80, description: "d10"},
    {id: 11, name: "Spencer Gordon", score: 79, description: "d11"},
  ]
}

html:

<div class="container-fluid">
  <h1>Basic Use</h1>
  <es-ng-table [data]="data">
    <es-ng-table-col field="state" [checkbox]="true"></es-ng-table-col>
    <es-ng-table-col title="ID" field="id"></es-ng-table-col>
    <es-ng-table-col title="Name" field="name"></es-ng-table-col>
    <es-ng-table-col title="Score" field="score"></es-ng-table-col>
    <es-ng-table-col title="Description" field="description"></es-ng-table-col>
  </es-ng-table>
</div>

General Search

html:

<es-ng-table [data]="data">
    <es-ng-table-tool-bar>
      <es-ng-table-general-search></es-ng-table-general-search>
    </es-ng-table-tool-bar>
    <es-ng-table-col title="Name" field="name"></es-ng-table-col>
</es-ng-table>

Formatter and Text Template

ts:

export class AppComponent {
  formatter = (value: any) => {
    return value + ' postfix'
  }
}

html:

<es-ng-table [data]="data">
    <es-ng-table-col title="Name" field="name"></es-ng-table-col>
    <es-ng-table-col title="Score" field="score">
      <ng-template #textTemplate let-row="row" let-value="value" let-index="index" let-formatter="formatter">
        <button>{{value}}</button>
      </ng-template>
    </es-ng-table-col>
    <es-ng-table-col title="Description" field="description" [formatter]="formatter"></es-ng-table-col>
</es-ng-table>

Keep

IMPORTANT: NEED IMPORT "RouterModule". ONLY ONE KEEP IN ONE PAGE.

you will see url change after any params changes(like: page, size, search...)

html:

<es-ng-table [data]="data" [keep]="true"></es-ng-table>

Fetch Data From API

html:

<es-ng-table url="http://domain/path">
   <es-ng-table-col field="state" [checkbox]="true"></es-ng-table-col>
   <es-ng-table-col title="ID" field="id"></es-ng-table-col>
   <es-ng-table-col title="Name" field="name"></es-ng-table-col>
</es-ng-table>

Variable

NgTableComponent & NgSdTableComponent

NameTypeDefaultDescription
dataArraydata of rows.
rowsArray[]current data of rows.
totalnumbersize of total data.
pagenumber1current page.
sizenumber10size in a page.
searchstringsearch text, used in general search.
querystringquery json, user in advanced search.
sortstringsort by field.
order'asc' 'desc''asc'order.
urlstringget json from url.
keepbooleanfalsekeep search result.

NgTableColComponent

NameTypeDefaultDescription
titlestringth text.
fieldstringfield name in row.
checkboxbooleanfalseis checkbox cell?
radiobooleanfalseis radio cell?

Method

NgTableComponent & NgSdTableComponent

NameParamReturnDescription
refreshvoidrefresh rows.
generalSearch(term: string)voidgeneral search.
advancedSearch(query: any)voidadvance search.
getSelectionsArrayget selected rows.

Input

NgTableComponent & NgSdTableComponent

NameTypeDefaultDescription
dataArraydata of rows.
urlstringget json from url.
sortstringsort by field.
order'asc' 'desc''asc'order.
keepbooleanfalsekeep search result.
queryFunFunction(client pagination) advanced search. (row: any, index: number, query: any) => Array
responseHandlerFunctionhandler after get data from url. (data: any) => any

NgTableColComponent

NameTypeDefaultDescription
titlestringth text.
fieldstringfield name in row.
checkboxbooleanfalseis checkbox cell?
radiobooleanfalseis radio cell?
formatterFunctionformatter cell. (value: any) => string

Output

NgTableComponent & NgSdTableComponent

NameTypeDescription
onRowClickanyfired when row be clicked.

NgTableColComponent

NameTypeDescription
onCellClickanyfired when cell be clicked.
1.0.1

6 years ago

1.0.0

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago