-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataGridComponent.ts
More file actions
195 lines (159 loc) · 4.98 KB
/
DataGridComponent.ts
File metadata and controls
195 lines (159 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { AgGridModule } from 'ag-grid-angular';
import { AppComponent } from './app.component';
import { DataGridComponent } from './components/data-grid.component';
@NgModule({
declarations: [
AppComponent,
DataGridComponent
],
imports: [
BrowserModule,
HttpClientModule,
AgGridModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
// app.component.html
/*
<div class="app-container">
<h1>Employee Data Grid - Server Side Row Model</h1>
<app-data-grid></app-data-grid>
</div>
*/
// app.component.css
/*
.app-container {
padding: 20px;
font-family: Arial, sans-serif;
}
h1 {
color: #333;
margin-bottom: 20px;
}
*/
// Installation and Setup Instructions
/*
INSTALLATION STEPS:
1. Install required npm packages:
npm install ag-grid-community ag-grid-angular
2. Install ag-Grid theme CSS (add to angular.json):
"styles": [
"node_modules/ag-grid-community/styles/ag-grid.css",
"node_modules/ag-grid-community/styles/ag-theme-alpine.css",
"src/styles.css"
]
3. If using ag-Grid Enterprise features, install:
npm install ag-grid-enterprise
Then import in your main module:
import 'ag-grid-enterprise';
4. Backend Setup:
- Ensure your C# Web API project has the necessary packages:
- Microsoft.AspNetCore.Mvc
- Microsoft.Extensions.Configuration
- System.Data (for DataTable)
- Configure connection string in appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Your connection string here"
}
}
5. CORS Configuration:
Make sure CORS is properly configured in your C# backend to allow
requests from your Angular development server (typically http://localhost:4200)
ADVANCED FEATURES YOU CAN ADD:
1. Custom Cell Renderers:
- Add action buttons (edit, delete, view)
- Status indicators
- Progress bars
- Images/avatars
2. Advanced Filtering:
- Date range filters
- Multi-select filters
- Custom filter components
3. Grouping and Aggregation:
- Group by department, status, etc.
- Sum, average, count aggregations
4. Export Features:
- Excel export
- PDF export
- Custom export formats
5. Real-time Updates:
- SignalR integration
- WebSocket connections
- Automatic refresh
6. Performance Optimizations:
- Caching strategies
- Database indexing
- Lazy loading
CONFIGURATION OPTIONS:
Row Model Settings:
- cacheBlockSize: Number of rows to fetch per request (default: 100)
- maxBlocksInCache: Maximum blocks to keep in memory (default: 10)
- serverSideInfiniteScroll: Enable infinite scrolling (default: false)
Grid Features:
- enableRangeSelection: Allow cell range selection
- enableCharts: Enable integrated charting
- animateRows: Animate row changes
- suppressColumnVirtualisation: Show all columns (performance impact)
Performance Tips:
1. Use appropriate block sizes (100-1000 rows)
2. Implement proper indexing on sorted/filtered columns
3. Use pagination for very large datasets
4. Consider using database views for complex queries
5. Implement caching at the service level
TROUBLESHOOTING:
Common Issues:
1. CORS errors: Check backend CORS configuration
2. Data not loading: Verify API endpoint and request format
3. Sorting/filtering not working: Check backend implementation
4. Performance issues: Adjust block size and caching settings
*/
// Enhanced data grid service for more advanced scenarios
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, BehaviorSubject } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class DataGridService {
private readonly baseUrl = '/api/employees';
private loadingSubject = new BehaviorSubject<boolean>(false);
public loading$ = this.loadingSubject.asObservable();
constructor(private http: HttpClient) {}
getServerSideData(request: any): Observable<any> {
this.loadingSubject.next(true);
return this.http.post<any>(`${this.baseUrl}/serverside`, request)
.pipe(
map(response => {
this.loadingSubject.next(false);
return response;
}),
catchError(error => {
this.loadingSubject.next(false);
throw error;
})
);
}
exportData(filters: any, sortModel: any): Observable<Blob> {
const params = new HttpParams()
.set('filters', JSON.stringify(filters))
.set('sortModel', JSON.stringify(sortModel));
return this.http.get(`${this.baseUrl}/export`, {
params,
responseType: 'blob'
});
}
getDepartments(): Observable<string[]> {
return this.http.get<string[]>(`${this.baseUrl}/departments`);
}
getColumnStatistics(columnName: string): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/statistics/${columnName}`);
}
}