@bhplugin/ng-datatable

中文文档
0.2.0发布于 2025/09/15MITTypeScriptES Module近 30 天下载 2841

ng-datatable - fully customizable & easy to use datatable library

原始使用文档
文档目录11 节
  1. Example
  2. Install
  3. Usage
  4. Props
  5. Columns options
  6. Events
  7. Methods
  8. License
  9. Our other plugins
  10. Vue3 Datatable - @bhplugin/vue3-datatable
  11. Support

@bhplugin/ng-datatable


Example

Document & Demos

Install

NPM

npm install @bhplugin/ng-datatable --save

Yarn

yarn add @bhplugin/ng-datatable

Bower

bower install @bhplugin/ng-datatable --save

Usage

app.module.ts

import { NgModule } from '@angular/core';
import { DataTableModule } from '@bhplugin/ng-datatable';

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

app.component.html

<ng-datatable [rows]="rows" [columns]="cols"> </ng-datatable>

app.component.ts


import { Component } from '@angular/core';
import { colDef } from '@bhplugin/ng-datatable';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})

export class AppComponent {
    cols: Array<colDef> = [];
    rows: Array<any> = [];

    constructor() {
        this.initData();
    }

    initData(){
        this.cols = [
            { field: "id", title: "ID", filter: false },
            { field: "name", title: "Name" },
            { field: "username", title: "Username" },
            { field: "email", title: "Email" },
            { field: "phone", title: "Phone" },
            { field: "date", title: "Date", type: "date" },
            { field: "active", title: "Active", type: "bool" },
            { field: "age", title: "Age", type: "number" },
            { field: "address.city", title: "Address" },
            { field: "company.name", title: "Company" },
        ];

        this.rows = [
            {
            id: 1,
            name: "Leanne Graham",
            username: "Bret",
            email: "[email protected]",
            address: {
                street: "Kulas Light",
                suite: "Apt. 556",
                city: "Gwenborough",
                zipcode: "92998-3874",
                geo: {
                    lat: "-37.3159",
                    lng: "81.1496",
                },
            },
            phone: "1-770-736-8031 x56442",
            website: "hildegard.org",
            company: {
                name: "Romaguera-Crona",
                catchPhrase: "Multi-layered client-server neural-net",
                bs: "harness real-time e-markets",
            },
            date: "Tue Sep 27 2022 22:19:57",
            age: 10,
            active: true,
            },
            .......
        ];
    }
}

Props

PropsTypeDefaultDescription
columns (required)array[]table columns
rows (required)array[]table rows
isServerModebooleanfalseset true if you need server side pagination.
totalRowsnumber0total number of rows. totalRows required when isServerMode is true
skinstring"bh-table-striped bh-table-hover"custom class for skin ('bh-table-striped' - for stripe row, 'bh-table-hover' - for hover row, 'bh-table-bordered' - for bordered row, 'bh-table-compact' - for compact table)
loadingbooleanfalseenable loader
hasCheckboxbooleanfalseenable checkbox
searchstring""enable global search
pagenumber1current page
pageSizenumber10number of rows per page
pageSizeOptionsarray[10, 20, 30, 50, 100]pagesize options
showPageSizebooleantrueenable pagesize options
rowClassarray, function""custom row class
cellClassarray, function""custom cell class
sortablebooleantrueenable sorting
sortColumnstring"id"name of sort column
sortDirectionstring"asc"sort direction (asc or desc)
columnFilterbooleanfalseenable individual column filter
paginationbooleantrueenable pagination
showNumbersbooleantrueenable numbers pagination
showNumbersCountnumber5show numbers of count in pagination
showFirstPagebooleantrueenable first page in pagination
showLastPagebooleantrueenable last page in pagination
firstArrowstringdefault arrowcustom first page arrow
lastArrowstringdefault arrowcustom last page arrow
previousArrowstringdefault arrowcustom previous page arrow
nextArrowstringdefault arrowcustom next page arrow
paginationInfostring"Showing {0} to {1} of {2} entries"custom pagination info
noDataContentstringNo data availablecustom no data message
stickyHeaderbooleanfalseenable fixed header
heightstring450pxonly will be used when stickyHeader enabled
stickyFirstColumnbooleanfalseenable fixed first column
cloneHeaderInFooterbooleanfalseenable clone header in footer
selectRowOnClickbooleanfalseenable to select row(checkbox) on row click

Columns options

PropsTypeDefaultDescription
isUniquebooleanfalsedb column is primary key or not
fieldstring""db column name
titlestring""display column name
valuestring""filter value if filter enabled
conditionstring"contain"default condition for column filter if filter enabled
typestring""column type (string, date, number, bool)
widthstring""custom width of column
minWidthstring""custom minimum width of column
maxWidthstring""custom maximum width of column
hidebooleanfalseshow/hide column
filterbooleantrueenable column filter
searchbooleantrueenabled global search
sortbooleantrueenable sorting
cellRendererfunction, stringcustom cell rendering
headerClassstring""custom header cell class
cellClassstring""custom cell class

Events

NameDescription
sortChangewill trigger when sorting changed
searchChangewill trigger when search changed
pageChangewill trigger when page changed
pageSizeChangewill trigger when pagesize changed
rowSelectwill trigger when row selected using checkbox
filterChangewill trigger when column filter changed
rowClickwill trigger when row clicked
rowDBClickwill trigger when row double clicked

Methods

NameDescription
resetwill reset all options like selected rows, filter, search, currennt page etc
getSelectedRowswill returns all selected rows
getColumnFilterswill return all column filters
clearSelectedRowswill unselect all selected rows
selectRow(index)will select row with the given index (non-existent row will be ignored)
unselectRow(index)will unselect row with the given index (non-existent row will be ignored)
isRowSelected(index)will return true if the row with given index is selected

License

@bhplugin/ng-datatable is open-sourced software licensed under the MIT license.


Our other plugins

Vue3 Datatable - @bhplugin/vue3-datatable


Support

Buy Me A Coffee

版本与发布记录

@bhplugin/ng-datatable 共发布 4 个版本,首次发布于 2023/06/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2025/09/151.1 年前
0.1.02023/07/233 年前
0.0.22023/06/093 年前
0.0.12023/06/083 年前

关于 @bhplugin/ng-datatable 的常见问题

@bhplugin/ng-datatable 是什么?

ng-datatable - fully customizable & easy to use datatable library

如何安装 @bhplugin/ng-datatable?

在项目目录运行 npm install @bhplugin/ng-datatable,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(>=2.0.0)、@angular/core(>=2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bhplugin/ng-datatable 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bhplugin/ng-datatable 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bhplugin/ng-datatable 可以商用吗?

@bhplugin/ng-datatable 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bhplugin/ng-datatable 的下载量有多少?

根据 npm 官方下载统计,@bhplugin/ng-datatable 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,841 次,日均约 95 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bhplugin/ng-datatable 还在维护吗?

最新版本 0.2.0 发布于 2025/09/15(1.1 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/06/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。