-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDataGridContent.vue
More file actions
212 lines (202 loc) · 5.04 KB
/
Copy pathDataGridContent.vue
File metadata and controls
212 lines (202 loc) · 5.04 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<template>
<div id="app-container">
<DxDataGrid
id="dataGrid"
:data-source="employees"
key-expr="EmployeeID"
:allow-column-resizing="true"
:column-auto-width="true"
:allow-column-reordering="true"
@selection-changed="selectEmployee"
@exporting="exportGrid"
>
<DxColumn
data-field="FullName"
:fixed="true"
>
<DxRequiredRule/>
</DxColumn>
<DxColumn data-field="Position">
<DxRequiredRule/>
</DxColumn>
<DxColumn
data-field="BirthDate"
data-type="date"
:width="100"
>
<DxRequiredRule/>
</DxColumn>
<DxColumn
data-field="HireDate"
data-type="date"
:width="100"
>
<DxRequiredRule/>
</DxColumn>
<DxColumn data-field="City"/>
<DxColumn
data-field="Country"
:group-index="0"
sort-order="asc"
>
<DxRequiredRule/>
</DxColumn>
<DxColumn data-field="Address"/>
<DxColumn data-field="HomePhone"/>
<DxColumn
data-field="PostalCode"
:visible="false"
/>
<DxColumnChooser :enabled="true"/>
<DxColumnFixing :enabled="true"/>
<DxSorting mode="multiple"/>
<DxFilterRow :visible="true"/>
<DxSearchPanel :visible="true"/>
<DxGroupPanel :visible="true"/>
<DxSelection mode="single"/>
<DxSummary>
<DxGroupItem summary-type="count"/>
</DxSummary>
<DxEditing
mode="popup"
:allow-updating="true"
:allow-adding="true"
:allow-deleting="true"
/>
<DxGrouping :auto-expand-all="expanded"/>
<DxToolbar>
<DxItem name="groupPanel"/>
<DxItem
location="after"
template="button-template"
/>
<DxItem
name="addRowButton"
show-text="always"
/>
<DxItem name="exportButton"/>
<DxItem name="columnChooserButton"/>
<DxItem name="searchPanel"/>
</DxToolbar>
<template #button-template>
<DxButton
:text="expanded ? 'Collapse All' : 'Expand All'"
:width="136"
@click="expanded = !expanded"
/>
</template>
<DxMasterDetail
:enabled="true"
template="employee-info"
/>
<template #employee-info="{ data: employee }">
<div>
<img
class="employee-photo"
:src="employee.data.Photo"
:alt="employee.data.FullName"
>
<p class="employee-notes">{{ employee.data.Notes }}</p>
</div>
</template>
<DxExport
:enabled="true"
:formats="['xlsx', 'pdf']"
/>
</DxDataGrid>
<p
id="selected-employee"
v-if="selectedEmployee"
>
Selected employee: {{ selectedEmployee.FullName }}
</p>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import {
DxDataGrid,
DxColumn,
DxRequiredRule,
DxColumnChooser,
DxColumnFixing,
DxFilterRow,
DxSearchPanel,
DxGroupPanel,
DxSelection,
DxSummary,
DxGroupItem,
DxEditing,
DxGrouping,
DxToolbar,
DxItem,
DxMasterDetail,
DxExport,
DxSorting,
type DxDataGridTypes
} from 'devextreme-vue/data-grid';
import { DxButton } from 'devextreme-vue/button';
import { getEmployees, type Employee } from '../employees.service';
import { Workbook } from 'devextreme-exceljs-fork';
import { saveAs } from 'file-saver';
import { exportDataGrid } from 'devextreme/excel_exporter';
import { jsPDF } from 'jspdf';
import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
import 'devextreme/dist/css/dx.fluent.blue.light.css';
// Reactive data
const employees = ref<Employee[]>(getEmployees());
const selectedEmployee = ref<Employee | undefined>();
const expanded = ref<boolean>(true);
// Methods
function selectEmployee(e: DxDataGridTypes.SelectionChangedEvent): void {
e.component.byKey(e.currentSelectedRowKeys[0]).then((employee: Employee) => {
if (employee) {
selectedEmployee.value = employee;
}
});
}
function exportGrid(e: DxDataGridTypes.ExportingEvent): void {
if (e.format === 'xlsx') {
const workbook = new Workbook();
const worksheet = workbook.addWorksheet('Main sheet');
exportDataGrid({
worksheet: worksheet,
component: e.component,
}).then(() => {
workbook.xlsx.writeBuffer().then((buffer: ArrayBuffer) => {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx');
});
});
} else if (e.format === 'pdf') {
const doc = new jsPDF();
exportDataGridToPdf({
jsPDFDocument: doc,
component: e.component,
}).then(() => {
doc.save('DataGrid.pdf');
});
}
}
</script>
<style scoped>
.employee-photo {
height: 140px;
float: left;
padding: 0 20px 20px 0;
}
.employee-notes {
text-align: justify;
white-space: normal;
}
#dataGrid {
height: 500px;
}
#app-container {
position: relative;
}
#selected-employee {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
}
</style>