ng-dynamic-datatable 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,17 @@
1
+ # Editor configuration, see https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.ts]
12
+ quote_type = single
13
+ ij_typescript_use_double_quotes = false
14
+
15
+ [*.md]
16
+ max_line_length = off
17
+ trim_trailing_whitespace = false
@@ -0,0 +1,4 @@
1
+ {
2
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3
+ "recommendations": ["angular.ng-template"]
4
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3
+ "version": "0.2.0",
4
+ "configurations": [
5
+ {
6
+ "name": "ng serve",
7
+ "type": "chrome",
8
+ "request": "launch",
9
+ "preLaunchTask": "npm: start",
10
+ "url": "http://localhost:4200/"
11
+ },
12
+ {
13
+ "name": "ng test",
14
+ "type": "chrome",
15
+ "request": "launch",
16
+ "preLaunchTask": "npm: test",
17
+ "url": "http://localhost:9876/debug.html"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
3
+ "version": "2.0.0",
4
+ "tasks": [
5
+ {
6
+ "type": "npm",
7
+ "script": "start",
8
+ "isBackground": true,
9
+ "problemMatcher": {
10
+ "owner": "typescript",
11
+ "pattern": "$tsc",
12
+ "background": {
13
+ "activeOnStart": true,
14
+ "beginsPattern": {
15
+ "regexp": "(.*?)"
16
+ },
17
+ "endsPattern": {
18
+ "regexp": "bundle generation complete"
19
+ }
20
+ }
21
+ }
22
+ },
23
+ {
24
+ "type": "npm",
25
+ "script": "test",
26
+ "isBackground": true,
27
+ "problemMatcher": {
28
+ "owner": "typescript",
29
+ "pattern": "$tsc",
30
+ "background": {
31
+ "activeOnStart": true,
32
+ "beginsPattern": {
33
+ "regexp": "(.*?)"
34
+ },
35
+ "endsPattern": {
36
+ "regexp": "bundle generation complete"
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ]
42
+ }
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # NgDynamicDatatable
2
+
3
+ This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.27.
4
+
5
+ ## Development server
6
+
7
+ To start a local development server, run:
8
+
9
+ ```bash
10
+ ng serve
11
+ ```
12
+
13
+ Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
14
+
15
+ ## Code scaffolding
16
+
17
+ Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
18
+
19
+ ```bash
20
+ ng generate component component-name
21
+ ```
22
+
23
+ For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
24
+
25
+ ```bash
26
+ ng generate --help
27
+ ```
28
+
29
+ ## Building
30
+
31
+ To build the project run:
32
+
33
+ ```bash
34
+ ng build
35
+ ```
36
+
37
+ This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
38
+
39
+ ## Running unit tests
40
+
41
+ To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
42
+
43
+ ```bash
44
+ ng test
45
+ ```
46
+
47
+ ## Running end-to-end tests
48
+
49
+ For end-to-end (e2e) testing, run:
50
+
51
+ ```bash
52
+ ng e2e
53
+ ```
54
+
55
+ Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
56
+
57
+ ## Additional Resources
58
+
59
+ For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
package/angular.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3
+ "version": 1,
4
+ "cli": {
5
+ "packageManager": "npm",
6
+ "analytics": "b83209c5-de58-447d-b95e-ff75c77b7196"
7
+ },
8
+ "newProjectRoot": "projects",
9
+ "projects": {
10
+ "dynamic-datatable": {
11
+ "projectType": "library",
12
+ "root": "projects/dynamic-datatable",
13
+ "sourceRoot": "projects/dynamic-datatable/src",
14
+ "prefix": "lib",
15
+ "architect": {
16
+ "build": {
17
+ "builder": "@angular-devkit/build-angular:ng-packagr",
18
+ "options": {
19
+ "project": "projects/dynamic-datatable/ng-package.json"
20
+ },
21
+ "configurations": {
22
+ "production": {
23
+ "tsConfig": "projects/dynamic-datatable/tsconfig.lib.prod.json"
24
+ },
25
+ "development": {
26
+ "tsConfig": "projects/dynamic-datatable/tsconfig.lib.json"
27
+ }
28
+ },
29
+ "defaultConfiguration": "production"
30
+ },
31
+ "test": {
32
+ "builder": "@angular-devkit/build-angular:karma",
33
+ "options": {
34
+ "tsConfig": "projects/dynamic-datatable/tsconfig.spec.json",
35
+ "polyfills": [
36
+ "zone.js",
37
+ "zone.js/testing"
38
+ ]
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "ng-dynamic-datatable",
3
+ "version": "0.0.0",
4
+ "scripts": {
5
+ "ng": "ng",
6
+ "start": "ng serve",
7
+ "build": "ng build",
8
+ "watch": "ng build --watch --configuration development",
9
+ "test": "ng test"
10
+ },
11
+ "private": false,
12
+ "dependencies": {
13
+ "@angular/common": "^19.2.0",
14
+ "@angular/compiler": "^19.2.0",
15
+ "@angular/core": "^19.2.0",
16
+ "@angular/forms": "^19.2.0",
17
+ "@angular/platform-browser": "^19.2.0",
18
+ "@angular/platform-browser-dynamic": "^19.2.0",
19
+ "@angular/router": "^19.2.0",
20
+ "rxjs": "~7.8.0",
21
+ "tslib": "^2.3.0",
22
+ "zone.js": "~0.15.0"
23
+ },
24
+ "devDependencies": {
25
+ "@angular-devkit/build-angular": "^19.2.27",
26
+ "@angular/cli": "^19.2.27",
27
+ "@angular/compiler-cli": "^19.2.0",
28
+ "@types/jasmine": "~5.1.0",
29
+ "jasmine-core": "~5.6.0",
30
+ "karma": "~6.4.0",
31
+ "karma-chrome-launcher": "~3.2.0",
32
+ "karma-coverage": "~2.2.0",
33
+ "karma-jasmine": "~5.1.0",
34
+ "karma-jasmine-html-reporter": "~2.1.0",
35
+ "ng-packagr": "^19.2.0",
36
+ "typescript": "~5.7.2"
37
+ }
38
+ }
@@ -0,0 +1,134 @@
1
+ # dynamic-datatable
2
+
3
+ Config-driven Angular DataTable library that accepts columns, JSON data, and feature configuration.
4
+
5
+ ## Features
6
+
7
+ - Dynamic columns and data inputs
8
+ - Sorting (column-wise)
9
+ - Searching across visible columns
10
+ - Pagination and rows-per-page selection
11
+ - Row selection and select-all
12
+ - Row action events
13
+ - CSV and Excel export
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install dynamic-datatable
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Import the standalone component directly in your consuming component:
24
+
25
+ ```ts
26
+ import { Component } from '@angular/core';
27
+ import {
28
+ DynamicDatatableComponent,
29
+ DynamicDataTableConfig,
30
+ DataTableColumn
31
+ } from 'dynamic-datatable';
32
+
33
+ @Component({
34
+ selector: 'app-users',
35
+ standalone: true,
36
+ imports: [DynamicDatatableComponent],
37
+ template: `
38
+ <lib-dynamic-datatable
39
+ [config]="config"
40
+ [columns]="columns"
41
+ [data]="rows"
42
+ (actionSelected)="onAction($event)"
43
+ (selectionChange)="onSelection($event)"
44
+ />
45
+ `
46
+ })
47
+ export class UsersComponent {
48
+ rows = [
49
+ { id: 1, name: 'Aarav Sharma', email: 'aarav.sharma@company.in', salary: '19366.53', status: 'Resigned' },
50
+ { id: 2, name: 'Ananya Patel', email: 'ananya.patel@company.in', salary: '10745.32', status: 'Applied' }
51
+ ];
52
+
53
+ columns: DataTableColumn[] = [
54
+ { key: 'name', label: 'Name', sortable: true, width: '220px' },
55
+ { key: 'email', label: 'Email', sortable: true, width: '260px' },
56
+ { key: 'salary', label: 'Salary', sortable: true, width: '120px' },
57
+ {
58
+ key: 'status',
59
+ label: 'Status',
60
+ sortable: true,
61
+ render: (row) => `<span>${row['status']}</span>`
62
+ }
63
+ ];
64
+
65
+ config: DynamicDataTableConfig = {
66
+ title: 'Users',
67
+ features: {
68
+ export: true,
69
+ sorting: true,
70
+ searching: true,
71
+ pagination: true,
72
+ rowsPerPage: true,
73
+ actions: true,
74
+ checkboxSelection: true
75
+ },
76
+ rowsPerPageOptions: [5, 10, 25],
77
+ defaultRowsPerPage: 10,
78
+ exportOptions: { fileName: 'users-export', formats: ['csv', 'excel'] },
79
+ actions: [
80
+ { label: 'Details', id: 'details' },
81
+ { label: 'Delete', id: 'delete', danger: true }
82
+ ]
83
+ };
84
+
85
+ onAction(event: unknown): void {
86
+ console.log(event);
87
+ }
88
+
89
+ onSelection(rows: unknown[]): void {
90
+ console.log(rows);
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Component API
96
+
97
+ Inputs:
98
+
99
+ - `config: DynamicDataTableConfig`
100
+ - `columns: DataTableColumn[]`
101
+ - `data: Record<string, unknown>[]`
102
+
103
+ Outputs:
104
+
105
+ - `actionSelected`
106
+ - `selectionChange`
107
+ - `sortChange`
108
+ - `pageChange`
109
+ - `exportTriggered`
110
+
111
+ Public methods:
112
+
113
+ - `refresh()`
114
+ - `updateData(newData)`
115
+ - `updateConfig(newConfig)`
116
+ - `getSelectedRows()`
117
+ - `clearSelection()`
118
+
119
+ ## Build
120
+
121
+ ```bash
122
+ ng build dynamic-datatable
123
+ ```
124
+
125
+ Artifacts are generated in `dist/dynamic-datatable`.
126
+
127
+ ## Publish to npm
128
+
129
+ ```bash
130
+ cd dist/dynamic-datatable
131
+ npm publish --access public
132
+ ```
133
+
134
+ Before publishing, ensure the package name in `projects/dynamic-datatable/package.json` is unique on npm.
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/dynamic-datatable",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "dynamic-datatable",
3
+ "version": "0.0.1",
4
+ "description": "Config-driven Angular DataTable library with sorting, searching, pagination, selection, and export.",
5
+ "keywords": [
6
+ "angular",
7
+ "datatable",
8
+ "table",
9
+ "grid",
10
+ "sorting",
11
+ "pagination",
12
+ "search"
13
+ ],
14
+ "author": "",
15
+ "license": "MIT",
16
+ "peerDependencies": {
17
+ "@angular/common": "^19.2.0",
18
+ "@angular/core": "^19.2.0"
19
+ },
20
+ "dependencies": {
21
+ "tslib": "^2.3.0"
22
+ },
23
+ "sideEffects": false
24
+ }
@@ -0,0 +1,137 @@
1
+ <div class="ndt-card">
2
+ <div class="ndt-header">
3
+ <h3 class="ndt-title">{{ mergedConfig.title }}</h3>
4
+ </div>
5
+
6
+ <div class="ndt-toolbar">
7
+ <div class="ndt-left-tools">
8
+ <ng-container *ngIf="isFeatureOn('export')">
9
+ <button class="ndt-btn" type="button" (click)="exportCSV()" *ngIf="isExportFormatEnabled('csv')">
10
+ Export CSV
11
+ </button>
12
+ <button class="ndt-btn" type="button" (click)="exportExcel()" *ngIf="isExportFormatEnabled('excel')">
13
+ Export Excel
14
+ </button>
15
+ </ng-container>
16
+
17
+ <label class="ndt-inline-label" *ngIf="isFeatureOn('rowsPerPage') && isFeatureOn('pagination')">
18
+ Rows per page:
19
+ <select [value]="rowsPerPage" (change)="onRowsPerPageChange($event)">
20
+ <option *ngFor="let option of mergedConfig.rowsPerPageOptions || []" [value]="option">{{ option }}</option>
21
+ </select>
22
+ </label>
23
+ </div>
24
+
25
+ <div class="ndt-right-tools" *ngIf="isFeatureOn('searching')">
26
+ <input
27
+ type="search"
28
+ placeholder="Search records"
29
+ [value]="searchTerm"
30
+ (input)="onSearchInput($event)"
31
+ />
32
+ </div>
33
+ </div>
34
+
35
+ <div class="ndt-table-wrap">
36
+ <table class="ndt-table">
37
+ <colgroup>
38
+ <col *ngIf="isFeatureOn('checkboxSelection')" style="width: 44px" />
39
+ <col *ngFor="let column of mergedColumns" [style.width]="toColumnWidth(column.width)" />
40
+ <col *ngIf="isFeatureOn('actions')" style="width: 78px" />
41
+ </colgroup>
42
+
43
+ <thead>
44
+ <tr>
45
+ <th *ngIf="isFeatureOn('checkboxSelection')">
46
+ <input
47
+ type="checkbox"
48
+ [checked]="isCurrentPageFullySelected()"
49
+ (change)="toggleSelectAllCurrentPage($event)"
50
+ />
51
+ </th>
52
+ <th
53
+ *ngFor="let column of mergedColumns"
54
+ [class.ndt-sortable]="isFeatureOn('sorting') && !!column.sortable"
55
+ (click)="toggleSort(column)"
56
+ >
57
+ <span class="ndt-th-content">
58
+ <span class="ndt-th-label">{{ column.label }}</span>
59
+ <span class="ndt-sort-indicator" *ngIf="isFeatureOn('sorting') && column.sortable">
60
+ {{ getSortIndicator(column.key.toString()) }}
61
+ </span>
62
+ </span>
63
+ </th>
64
+ <th *ngIf="isFeatureOn('actions')">Actions</th>
65
+ </tr>
66
+ </thead>
67
+
68
+ <tbody>
69
+ <tr *ngIf="!pagedRows.length">
70
+ <td [attr.colspan]="getColumnCount()" class="ndt-empty">No records found.</td>
71
+ </tr>
72
+
73
+ <tr *ngFor="let row of pagedRows; let rowIndex = index" [class.ndt-selected]="isRowSelected(row.id)">
74
+ <td *ngIf="isFeatureOn('checkboxSelection')">
75
+ <input
76
+ type="checkbox"
77
+ [checked]="isRowSelected(row.id)"
78
+ (change)="toggleRowSelection(row, $event)"
79
+ />
80
+ </td>
81
+
82
+ <td *ngFor="let column of mergedColumns" [innerHTML]="getRenderedCell(row.data, column)"></td>
83
+
84
+ <td *ngIf="isFeatureOn('actions')" class="ndt-actions-cell">
85
+ <div class="ndt-dropdown" (click)="$event.stopPropagation()">
86
+ <button
87
+ type="button"
88
+ class="ndt-actions-btn"
89
+ (click)="toggleActionMenu(row.id, $event)"
90
+ [attr.aria-expanded]="isActionMenuOpen(row.id)"
91
+ >
92
+ <span class="ndt-dots">...</span>
93
+ </button>
94
+
95
+ <ul class="ndt-dropdown-menu" *ngIf="isActionMenuOpen(row.id)">
96
+ <li *ngFor="let action of mergedConfig.actions || []; let i = index">
97
+ <button
98
+ type="button"
99
+ class="ndt-dropdown-item"
100
+ [class.ndt-danger]="!!action.danger"
101
+ (click)="onActionItemClick(i, row)"
102
+ >
103
+ <i *ngIf="action.icon" [class]="action.icon"></i>
104
+ <span>{{ action.label }}</span>
105
+ </button>
106
+ </li>
107
+ </ul>
108
+ </div>
109
+ </td>
110
+ </tr>
111
+ </tbody>
112
+ </table>
113
+ </div>
114
+
115
+ <div class="ndt-footer">
116
+ <div>
117
+ {{ selectedRows.size }} selected
118
+ </div>
119
+
120
+ <div>
121
+ Showing {{ getStartEntry() }} to {{ getEndEntry() }} of {{ filteredRows.length }} entries
122
+ </div>
123
+
124
+ <div class="ndt-pagination" *ngIf="isFeatureOn('pagination') && totalPages > 1">
125
+ <button type="button" (click)="goToPage(currentPage - 1)" [disabled]="currentPage <= 1">Prev</button>
126
+ <button
127
+ type="button"
128
+ *ngFor="let page of getPaginationPages()"
129
+ [class.active]="page === currentPage"
130
+ (click)="goToPage(page)"
131
+ >
132
+ {{ page }}
133
+ </button>
134
+ <button type="button" (click)="goToPage(currentPage + 1)" [disabled]="currentPage >= totalPages">Next</button>
135
+ </div>
136
+ </div>
137
+ </div>