-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-grid.component.ts
More file actions
90 lines (84 loc) · 2.39 KB
/
data-grid.component.ts
File metadata and controls
90 lines (84 loc) · 2.39 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
// data-grid.component.ts
import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { DetailDialogComponent } from './detail-dialog.component';
import { GridOptions } from 'ag-grid-community';
@Component({
selector: 'app-data-grid',
template: `
<div style="height: 600px; width: 100%;">
<ag-grid-angular
style="width: 100%; height: 100%;"
class="ag-theme-material"
[gridOptions]="gridOptions"
[rowData]="rowData"
(gridReady)="onGridReady($event)">
</ag-grid-angular>
</div>
`,
styles: [`
:host {
display: block;
width: ",
height: 100%;
}
`]
})
export class DataGridComponent implements OnInit {
gridOptions: GridOptions;
rowData: any[] = [];
constructor(private dialog: MatDialog) {
this.gridOptions = {
masterDetail: true,
detailCellRendererParams: {
detailGridOptions: {
columnDefs: [
{ field: 'id', headerName: 'ID' },
{ field: 'description', headerName: 'Description' },
{ field: 'value', headerName: 'Value' }
],
onRowClicked: (params) => this.onDetailRowClicked(params)
},
getDetailRowData: (params) => {
params.successCallback(this.getDetailData(params.data));
}
},
columnDefs: [
{ field: 'name', headerName: 'Name', rowGroup: true },
{ field: 'id', headerName: 'ID' },
{ field: 'status', headerName: 'Status' }
],
defaultColDef: {
sortable: true,
filter: true,
resizable: true
}
};
}
ngOnInit() {
// Sample master data
this.rowData = [
{ id: 1, name: 'Item 1', status: 'Active' },
{ id: 2, name: 'Item 2', status: 'Inactive' },
{ id: 3, name: 'Item 3', status: 'Active' }
];
}
onGridReady(params: any) {
params.api.sizeColumnsToFit();
}
getDetailData(masterRow: any) {
// Sample detail data
return [
{ id: `${masterRow.id}-1`, description: `Detail for ${masterRow.name}`, value: 100 },
{ id: `${masterRow.id}-2`, description: `Another detail`, value: 200 }
];
}
onDetailRowClicked(params: any) {
this.dialog.open(DetailDialogComponent, {
width: '400px',
data: {
message: `Selected detail row: ${params.data.description} with value ${params.data.value}`
}
});
}
}