1
1
# NgxSimpleDatatable
2
2
3
3
A lightweight, high-performance Angular data table component with features like virtual scrolling, column freezing, and customizable templates.
4
+ .
4
5
5
6
## Features
6
7
@@ -23,33 +24,34 @@ npm install ngx-simple-datatable --save
23
24
1 . Import the module in your ` app.module.ts ` :
24
25
25
26
``` typescript
26
- import { NgxSimpleDatatableModule } from ' ngx-simple-datatable' ;
27
+ import { NgxSimpleDatatableModule } from " ngx-simple-datatable" ;
27
28
28
29
@NgModule ({
29
30
imports: [
30
31
// ... other imports
31
- NgxSimpleDatatableModule
32
- ]
32
+ NgxSimpleDatatableModule ,
33
+ ],
33
34
})
34
- export class AppModule { }
35
+ export class AppModule {}
35
36
```
36
37
37
38
2 . Use the component in your template:
38
39
39
40
``` html
40
- <ngx-simple-datatable
41
- [columns] =" columns"
41
+ <ngx-simple-datatable
42
+ [columns] =" columns"
42
43
[data] =" data"
43
44
[rowHeight] =" 40"
44
- [headerHeight] =" 50" >
45
+ [headerHeight] =" 50"
46
+ >
45
47
</ngx-simple-datatable >
46
48
```
47
49
48
50
3 . Define your columns and data in your component:
49
51
50
52
``` typescript
51
- import { Component } from ' @angular/core' ;
52
- import { ColumnConfig } from ' ngx-simple-datatable' ;
53
+ import { Component } from " @angular/core" ;
54
+ import { ColumnConfig } from " ngx-simple-datatable" ;
53
55
54
56
interface UserData {
55
57
id: number ;
@@ -59,21 +61,26 @@ interface UserData {
59
61
}
60
62
61
63
@Component ({
62
- selector: ' app-root' ,
63
- templateUrl: ' ./app.component.html' ,
64
- styleUrls: [' ./app.component.css' ]
64
+ selector: " app-root" ,
65
+ templateUrl: " ./app.component.html" ,
66
+ styleUrls: [" ./app.component.css" ],
65
67
})
66
68
export class AppComponent {
67
69
columns: ColumnConfig [] = [
68
- { field: ' id ' , header: ' ID ' , width: ' 80px' , freeze: ' left' },
69
- { field: ' name' , header: ' Name' , width: ' 200px' , sortable: true },
70
- { field: ' email' , header: ' Email' , width: ' 250px' },
71
- { field: ' status' , header: ' Status' , width: ' 120px' }
70
+ { field: " id " , header: " ID " , width: " 80px" , freeze: " left" },
71
+ { field: " name" , header: " Name" , width: " 200px" , sortable: true },
72
+ { field: " email" , header: " Email" , width: " 250px" },
73
+ { field: " status" , header: " Status" , width: " 120px" },
72
74
];
73
75
74
76
data: UserData [] = [
75
- { id:
1 , name:
' John Doe' , email:
' [email protected] ' , status:
' Active' },
76
- { id:
2 , name:
' Jane Smith' , email:
' [email protected] ' , status:
' Inactive' },
77
+ { id:
1 , name:
" John Doe" , email:
" [email protected] " , status:
" Active" },
78
+ {
79
+ id: 2 ,
80
+ name: " Jane Smith" ,
81
+
82
+ status: " Inactive" ,
83
+ },
77
84
// ... more data
78
85
];
79
86
}
@@ -103,16 +110,16 @@ Use Angular templates to customize cell content:
103
110
<ng-template #cellTemplate let-row =" row" let-column =" column" >
104
111
<ng-container [ngSwitch] =" column.field" >
105
112
<ng-container *ngSwitchCase =" 'status'" >
106
- <span [ngClass] =" {
113
+ <span
114
+ [ngClass] =" {
107
115
'status-active': row[column.field] === 'Active',
108
116
'status-inactive': row[column.field] !== 'Active'
109
- }" >
117
+ }"
118
+ >
110
119
{{ row[column.field] }}
111
120
</span >
112
121
</ng-container >
113
- <ng-container *ngSwitchDefault >
114
- {{ row[column.field] }}
115
- </ng-container >
122
+ <ng-container *ngSwitchDefault > {{ row[column.field] }} </ng-container >
116
123
</ng-container >
117
124
</ng-template >
118
125
</ngx-simple-datatable >
@@ -154,24 +161,24 @@ Customize the table appearance using CSS custom properties:
154
161
155
162
### Inputs
156
163
157
- | Input | Type | Description |
158
- | -------| ------| -------------|
159
- | ` [columns] ` | ` ColumnConfig[] ` | Array of column configurations |
160
- | ` [data] ` | ` any[] ` | Array of data to display |
161
- | ` [rowHeight] ` | ` number ` | Height of each row in pixels |
162
- | ` [headerHeight] ` | ` number ` | Height of the header row in pixels |
163
- | ` [bufferSize] ` | ` number ` | Number of rows to render outside viewport for smooth scrolling |
164
+ | Input | Type | Description |
165
+ | ---------------- | ---------------- | -------------------------------------------------------------- |
166
+ | ` [columns] ` | ` ColumnConfig[] ` | Array of column configurations |
167
+ | ` [data] ` | ` any[] ` | Array of data to display |
168
+ | ` [rowHeight] ` | ` number ` | Height of each row in pixels |
169
+ | ` [headerHeight] ` | ` number ` | Height of the header row in pixels |
170
+ | ` [bufferSize] ` | ` number ` | Number of rows to render outside viewport for smooth scrolling |
164
171
165
172
### Column Configuration
166
173
167
- | Property | Type | Description |
168
- | ----------| ------| -------------|
169
- | ` field ` | ` string ` | Property name in the data object |
170
- | ` header ` | ` string ` | Column header text |
171
- | ` width ` | `string | number` | Column width (px or %) |
172
- | ` freeze ` | `'left' | 'right'` | Freeze column position |
173
- | ` sortable ` | ` boolean ` | Whether the column is sortable |
174
- | ` sortFn ` | ` (a: any, b: any) => number ` | Custom sort function |
174
+ | Property | Type | Description |
175
+ | ---------- | ---------------------------- | -------------------------------- | ---------------------- |
176
+ | ` field ` | ` string ` | Property name in the data object |
177
+ | ` header ` | ` string ` | Column header text |
178
+ | ` width ` | `string | number` | Column width (px or %) |
179
+ | ` freeze ` | `'left' | 'right'` | Freeze column position |
180
+ | ` sortable ` | ` boolean ` | Whether the column is sortable |
181
+ | ` sortFn ` | ` (a: any, b: any) => number ` | Custom sort function |
175
182
176
183
## Styling
177
184
0 commit comments