ngx-simple-datatables 1.17.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/README.md +222 -0
- package/esm2022/interfaces/column-config.interface.mjs +2 -0
- package/esm2022/lib/ngx-simple-datatable.component.mjs +483 -0
- package/esm2022/lib/ngx-simple-datatable.service.mjs +14 -0
- package/esm2022/ngx-simple-datatables.mjs +5 -0
- package/esm2022/public-api.mjs +6 -0
- package/fesm2022/ngx-simple-datatables.mjs +506 -0
- package/fesm2022/ngx-simple-datatables.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/interfaces/column-config.interface.d.ts +12 -0
- package/lib/ngx-simple-datatable.component.d.ts +78 -0
- package/lib/ngx-simple-datatable.service.d.ts +6 -0
- package/package.json +49 -0
- package/public-api.d.ts +2 -0
package/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# NgxSimpleDatatable
|
|
2
|
+
|
|
3
|
+
A lightweight, high-performance Angular data table component with features like virtual scrolling, column freezing, and customizable templates.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 📊 Virtual scrolling for smooth performance with large datasets
|
|
8
|
+
- ❄️ Freeze columns (left/right) for better data comparison
|
|
9
|
+
- 🔍 Sortable columns with custom sort functions
|
|
10
|
+
- 🎨 Customizable templates for headers and cells
|
|
11
|
+
- 📏 Resizable columns
|
|
12
|
+
- 🎨 Theming support with CSS custom properties
|
|
13
|
+
- ♿ Built with accessibility in mind
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install ngx-simple-datatable --save
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
1. Import the module in your `app.module.ts`:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { NgxSimpleDatatableModule } from "ngx-simple-datatable";
|
|
27
|
+
|
|
28
|
+
@NgModule({
|
|
29
|
+
imports: [
|
|
30
|
+
// ... other imports
|
|
31
|
+
NgxSimpleDatatableModule,
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
export class AppModule {}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Use the component in your template:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<ngx-simple-datatable
|
|
41
|
+
[columns]="columns"
|
|
42
|
+
[data]="data"
|
|
43
|
+
[rowHeight]="40"
|
|
44
|
+
[headerHeight]="50"
|
|
45
|
+
>
|
|
46
|
+
</ngx-simple-datatable>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
3. Define your columns and data in your component:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Component } from "@angular/core";
|
|
53
|
+
import { ColumnConfig } from "ngx-simple-datatable";
|
|
54
|
+
|
|
55
|
+
interface UserData {
|
|
56
|
+
id: number;
|
|
57
|
+
name: string;
|
|
58
|
+
email: string;
|
|
59
|
+
status: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Component({
|
|
63
|
+
selector: "app-root",
|
|
64
|
+
templateUrl: "./app.component.html",
|
|
65
|
+
styleUrls: ["./app.component.css"],
|
|
66
|
+
})
|
|
67
|
+
export class AppComponent {
|
|
68
|
+
columns: ColumnConfig[] = [
|
|
69
|
+
{ field: "id", header: "ID", width: "80px", freeze: "left" },
|
|
70
|
+
{ field: "name", header: "Name", width: "200px", sortable: true },
|
|
71
|
+
{ field: "email", header: "Email", width: "250px" },
|
|
72
|
+
{ field: "status", header: "Status", width: "120px" },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
data: UserData[] = [
|
|
76
|
+
{ id: 1, name: "John Doe", email: "john@example.com", status: "Active" },
|
|
77
|
+
{
|
|
78
|
+
id: 2,
|
|
79
|
+
name: "Jane Smith",
|
|
80
|
+
email: "jane@example.com",
|
|
81
|
+
status: "Inactive",
|
|
82
|
+
},
|
|
83
|
+
// ... more data
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Advanced Features
|
|
89
|
+
|
|
90
|
+
### Column Freezing
|
|
91
|
+
|
|
92
|
+
Freeze columns to the left or right for better data comparison:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
columns: ColumnConfig[] = [
|
|
96
|
+
{ field: 'id', header: 'ID', width: '80px', freeze: 'left' },
|
|
97
|
+
{ field: 'name', header: 'Name', width: '200px' },
|
|
98
|
+
{ field: 'email', header: 'Email', width: '250px' },
|
|
99
|
+
{ field: 'actions', header: 'Actions', width: '150px', freeze: 'right' }
|
|
100
|
+
];
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Custom Cell Templates
|
|
104
|
+
|
|
105
|
+
Use Angular templates to customize cell content:
|
|
106
|
+
|
|
107
|
+
```html
|
|
108
|
+
<ngx-simple-datatable [columns]="columns" [data]="data">
|
|
109
|
+
<ng-template #cellTemplate let-row="row" let-column="column">
|
|
110
|
+
<ng-container [ngSwitch]="column.field">
|
|
111
|
+
<ng-container *ngSwitchCase="'status'">
|
|
112
|
+
<span
|
|
113
|
+
[ngClass]="{
|
|
114
|
+
'status-active': row[column.field] === 'Active',
|
|
115
|
+
'status-inactive': row[column.field] !== 'Active'
|
|
116
|
+
}"
|
|
117
|
+
>
|
|
118
|
+
{{ row[column.field] }}
|
|
119
|
+
</span>
|
|
120
|
+
</ng-container>
|
|
121
|
+
<ng-container *ngSwitchDefault> {{ row[column.field] }} </ng-container>
|
|
122
|
+
</ng-container>
|
|
123
|
+
</ng-template>
|
|
124
|
+
</ngx-simple-datatable>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Custom Header Templates
|
|
128
|
+
|
|
129
|
+
Customize header appearance and behavior:
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<ngx-simple-datatable [columns]="columns" [data]="data">
|
|
133
|
+
<ng-template #headerTemplate let-column="column">
|
|
134
|
+
<div class="custom-header">
|
|
135
|
+
<i class="fas fa-info-circle" [title]="column.header"></i>
|
|
136
|
+
<span>{{ column.header }}</span>
|
|
137
|
+
<i class="fas fa-sort" *ngIf="column.sortable"></i>
|
|
138
|
+
</div>
|
|
139
|
+
</ng-template>
|
|
140
|
+
</ngx-simple-datatable>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Theming
|
|
144
|
+
|
|
145
|
+
Customize the table appearance using CSS custom properties:
|
|
146
|
+
|
|
147
|
+
```css
|
|
148
|
+
/* styles.css */
|
|
149
|
+
:root {
|
|
150
|
+
--ngx-simple-dt-header-bg: #f8f9fa;
|
|
151
|
+
--ngx-simple-dt-header-text: #2c3e50;
|
|
152
|
+
--ngx-simple-dt-row-hover-bg: #f1f3f5;
|
|
153
|
+
--ngx-simple-dt-row-stripe-bg: #f8f9fa;
|
|
154
|
+
--ngx-simple-dt-cell-padding: 0 16px;
|
|
155
|
+
--ngx-simple-dt-cell-border: 1px solid #e9ecef;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## API Reference
|
|
160
|
+
|
|
161
|
+
### Inputs
|
|
162
|
+
|
|
163
|
+
| Input | Type | Description |
|
|
164
|
+
| ---------------- | ---------------- | -------------------------------------------------------------- |
|
|
165
|
+
| `[columns]` | `ColumnConfig[]` | Array of column configurations |
|
|
166
|
+
| `[data]` | `any[]` | Array of data to display |
|
|
167
|
+
| `[rowHeight]` | `number` | Height of each row in pixels |
|
|
168
|
+
| `[headerHeight]` | `number` | Height of the header row in pixels |
|
|
169
|
+
| `[bufferSize]` | `number` | Number of rows to render outside viewport for smooth scrolling |
|
|
170
|
+
|
|
171
|
+
### Column Configuration
|
|
172
|
+
|
|
173
|
+
| Property | Type | Description |
|
|
174
|
+
| ---------- | ---------------------------- | -------------------------------- | ---------------------- |
|
|
175
|
+
| `field` | `string` | Property name in the data object |
|
|
176
|
+
| `header` | `string` | Column header text |
|
|
177
|
+
| `width` | `string | number` | Column width (px or %) |
|
|
178
|
+
| `freeze` | `'left' | 'right'` | Freeze column position |
|
|
179
|
+
| `sortable` | `boolean` | Whether the column is sortable |
|
|
180
|
+
| `sortFn` | `(a: any, b: any) => number` | Custom sort function |
|
|
181
|
+
|
|
182
|
+
## Styling
|
|
183
|
+
|
|
184
|
+
You can customize the table appearance by overriding the following CSS custom properties:
|
|
185
|
+
|
|
186
|
+
```css
|
|
187
|
+
.dynamic-table-container {
|
|
188
|
+
--ngx-simple-dt-bg: #ffffff;
|
|
189
|
+
--ngx-simple-dt-border: 1px solid #e0e0e0;
|
|
190
|
+
--ngx-simple-dt-border-radius: 8px;
|
|
191
|
+
--ngx-simple-dt-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
192
|
+
--ngx-simple-dt-transition: all 0.2s ease-in-out;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.table-header {
|
|
196
|
+
--ngx-simple-dt-header-bg: #f8f9fa;
|
|
197
|
+
--ngx-simple-dt-header-hover-bg: #e9ecef;
|
|
198
|
+
--ngx-simple-dt-header-border: 1px solid #e0e0e0;
|
|
199
|
+
--ngx-simple-dt-header-text: #495057;
|
|
200
|
+
--ngx-simple-dt-header-height: 48px;
|
|
201
|
+
--ngx-simple-dt-header-font-weight: 600;
|
|
202
|
+
--ngx-simple-dt-header-padding: 0 16px;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Development
|
|
207
|
+
|
|
208
|
+
Run `ng build ngx-simple-datatable` to build the library. The build artifacts will be stored in the `dist/` directory.
|
|
209
|
+
|
|
210
|
+
## Publishing
|
|
211
|
+
|
|
212
|
+
After building your library with `ng build ngx-simple-datatable`, go to the dist folder `cd dist/ngx-simple-datatable` and run `npm publish`.
|
|
213
|
+
|
|
214
|
+
After building your library with `ng build ngx-simple-datatable`, go to the dist folder `cd dist/ngx-simple-datatable` and run `npm publish`.
|
|
215
|
+
|
|
216
|
+
## Running unit tests
|
|
217
|
+
|
|
218
|
+
Run `ng test ngx-simple-datatable` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
219
|
+
|
|
220
|
+
## Further help
|
|
221
|
+
|
|
222
|
+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29sdW1uLWNvbmZpZy5pbnRlcmZhY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9uZ3gtc2ltcGxlLWRhdGF0YWJsZS9zcmMvaW50ZXJmYWNlcy9jb2x1bW4tY29uZmlnLmludGVyZmFjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGludGVyZmFjZSBDb2x1bW5Db25maWcge1xuICBmaWVsZDogc3RyaW5nO1xuICBoZWFkZXI6IHN0cmluZztcbiAgd2lkdGg/OiBzdHJpbmc7XG4gIGZyZWV6ZT86IFwibGVmdFwiIHwgXCJyaWdodFwiO1xuICBzb3J0YWJsZT86IGJvb2xlYW47XG4gIGZvcm1hdHRlcj86ICh2YWx1ZTogYW55LCByb3c6IGFueSkgPT4gc3RyaW5nO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIFNvcnRTdGF0ZSB7XG4gIGZpZWxkOiBzdHJpbmc7XG4gIGRpcmVjdGlvbjogXCJhc2NcIiB8IFwiZGVzY1wiIHwgbnVsbDtcbn1cbiJdfQ==
|