Commit c9f61969ad701658270431ae7bab95684f30602f
1 parent
375b62cd15
Exists in
master
and in
2 other branches
attendence download
Showing
2 changed files
with
83 additions
and
8 deletions
Show diff stats
src/pages/Attendence/viewStudentsAttendence.vue
... | ... | @@ -73,9 +73,8 @@ |
73 | 73 | <v-flex xs12> |
74 | 74 | <v-card-actions> |
75 | 75 | <v-spacer></v-spacer> |
76 | - <download-csv :data="json_data"> | |
77 | - <v-btn class="add-button" round @click.native="exportData">Export</v-btn> | |
78 | - </download-csv> | |
76 | + | |
77 | + <v-btn class="add-button" round @click="exportData">Export</v-btn> | |
79 | 78 | </v-card-actions> |
80 | 79 | </v-flex> |
81 | 80 | </v-layout> |
... | ... | @@ -378,6 +377,23 @@ export default { |
378 | 377 | // this.$router.replace({ path: '/' }); |
379 | 378 | }); |
380 | 379 | }, |
380 | + convertToCSV(objArray) { | |
381 | + var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; | |
382 | + var str = ''; | |
383 | + | |
384 | + for (var i = 0; i < array.length; i++) { | |
385 | + var line = ''; | |
386 | + for (var index in array[i]) { | |
387 | + if (line != '') line += ',' | |
388 | + | |
389 | + line += array[i][index]; | |
390 | + } | |
391 | + | |
392 | + str += line + '\r\n'; | |
393 | + } | |
394 | + | |
395 | + return str; | |
396 | + }, | |
381 | 397 | exportData() { |
382 | 398 | http() |
383 | 399 | .get( |
... | ... | @@ -396,6 +412,28 @@ export default { |
396 | 412 | .then(response => { |
397 | 413 | this.json_data = response.data.data; |
398 | 414 | this.dialogExport = false; |
415 | + console.log("hh",this.json_data) | |
416 | + var jsonObject = JSON.stringify(this.json_data); | |
417 | + | |
418 | + var csv = this.convertToCSV(jsonObject); | |
419 | + | |
420 | + var exportedFilenmae = "studentAttendance" + '.csv'; | |
421 | + var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); | |
422 | + if (navigator.msSaveBlob) { // IE 10+ | |
423 | + navigator.msSaveBlob(blob, exportedFilenmae); | |
424 | + } else { | |
425 | + var link = document.createElement("a"); | |
426 | + if (link.download !== undefined) { // feature detection | |
427 | + // Browsers that support HTML5 download attribute | |
428 | + var url = URL.createObjectURL(blob); | |
429 | + link.setAttribute("href", url); | |
430 | + link.setAttribute("download", exportedFilenmae); | |
431 | + link.style.visibility = 'hidden'; | |
432 | + document.body.appendChild(link); | |
433 | + link.click(); | |
434 | + document.body.removeChild(link); | |
435 | + } | |
436 | + } | |
399 | 437 | }) |
400 | 438 | .catch(err => { |
401 | 439 | console.log("err====>", err); | ... | ... |
src/pages/Attendence/viewTeacherAttendence.vue
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | <v-icon dark right size="20">save_alt</v-icon> |
13 | 13 | </v-btn> |
14 | 14 | <v-card flat class="card-style pa-2" dark> |
15 | - <h3 class=" title text-xs-center">Export</h3> | |
15 | + <h3 class="title text-xs-center">Export</h3> | |
16 | 16 | <v-card-text> |
17 | 17 | <v-container grid-list-md> |
18 | 18 | <v-layout wrap> |
... | ... | @@ -70,10 +70,9 @@ |
70 | 70 | </v-card-text> |
71 | 71 | <v-card-actions> |
72 | 72 | <v-spacer></v-spacer> |
73 | - <v-btn flat @click.native="dialogExport = false">Close</v-btn> | |
74 | - <download-csv :data="json_data"> | |
75 | - <v-btn flat @click.native="exportData">Export</v-btn> | |
76 | - </download-csv> | |
73 | + <v-btn flat @click.native="dialogExport = false">Close</v-btn> | |
74 | + | |
75 | + <v-btn flat @click.native="exportData">Export</v-btn> | |
77 | 76 | </v-card-actions> |
78 | 77 | </v-card> |
79 | 78 | </v-dialog> |
... | ... | @@ -365,6 +364,23 @@ export default { |
365 | 364 | // // this.$router.replace({ path: '/' }); |
366 | 365 | // }); |
367 | 366 | // }, |
367 | +convertToCSV(objArray) { | |
368 | + var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; | |
369 | + var str = ''; | |
370 | + | |
371 | + for (var i = 0; i < array.length; i++) { | |
372 | + var line = ''; | |
373 | + for (var index in array[i]) { | |
374 | + if (line != '') line += ',' | |
375 | + | |
376 | + line += array[i][index]; | |
377 | + } | |
378 | + | |
379 | + str += line + '\r\n'; | |
380 | + } | |
381 | + | |
382 | + return str; | |
383 | + }, | |
368 | 384 | exportData() { |
369 | 385 | // console.log("id",this.$route.params.teacherId); |
370 | 386 | http() |
... | ... | @@ -384,6 +400,27 @@ export default { |
384 | 400 | .then(response => { |
385 | 401 | this.json_data = response.data.data; |
386 | 402 | this.dialogExport = false; |
403 | + var jsonObject = JSON.stringify(this.json_data); | |
404 | + var csv = this.convertToCSV(jsonObject); | |
405 | + var exportedFilenmae = "teacherAttendance" + '.csv'; | |
406 | + var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); | |
407 | + if (navigator.msSaveBlob) { // IE 10+ | |
408 | + navigator.msSaveBlob(blob, exportedFilenmae); | |
409 | + } else { | |
410 | + var link = document.createElement("a"); | |
411 | + if (link.download !== undefined) { // feature detection | |
412 | + // Browsers that support HTML5 download attribute | |
413 | + var url = URL.createObjectURL(blob); | |
414 | + link.setAttribute("href", url); | |
415 | + link.setAttribute("download", exportedFilenmae); | |
416 | + link.style.visibility = 'hidden'; | |
417 | + document.body.appendChild(link); | |
418 | + link.click(); | |
419 | + document.body.removeChild(link); | |
420 | + } | |
421 | + } | |
422 | + | |
423 | + | |
387 | 424 | }) |
388 | 425 | .catch(err => { |
389 | 426 | console.log("err====>", err); | ... | ... |