-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExcelView.php
82 lines (70 loc) · 2.45 KB
/
ExcelView.php
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
<?php
namespace sateler;
use Yii;
use kartik\export\ExportMenu;
use kartik\grid\GridView;
class ExcelView extends GridView {
public $asButtonDropdown = true;
public $forceDownload = false;
public $exportMenu = [
ExportMenu::FORMAT_EXCEL_X => [
'label' => 'Exportar a Excel',
'icon' => 'floppy-save',
'linkOptions'=>[],
'options' => ['title' => 'Exportar a Excel'],
'confirmMsg' => '',
'mime' => 'application/vnd.ms-excel',
'extension' => 'xlsx',
'writer' => 'Excel2007',
'formatOptions' => [
'sheetTitle' => 'Hoja1',
]
],
ExportMenu::FORMAT_CSV => null,
ExportMenu::FORMAT_EXCEL => null,
ExportMenu::FORMAT_HTML => null,
ExportMenu::FORMAT_PDF => null,
ExportMenu::FORMAT_TEXT => null,
];
public $export = false;
public $layout = "{fullExport}\n{summary}\n{items}\n{pager}";
public $filename;
private $_columns;
private $_fullExport;
public function __construct($config = array()) {
$this->_columns = $config['columns'];
parent::__construct($config);
}
function init() {
parent::init();
if(!isset($this->replaceTags['{fullExport}'])) {
$this->replaceTags['{fullExport}'] = ExcelMenu::widget([
'dataProvider' => $this->dataProvider,
'filterModel' => $this->filterModel,
'columns' => $this->_columns,
'asDropdown' => $this->asButtonDropdown,
'exportConfig' => $this->exportMenu,
'showConfirmAlert' => false,
'target' => ExportMenu::TARGET_BLANK,
'filename' => $this->filename ?: $this->view->title ?: 'grid-export',
'enableFormatter' => false,
]);
}
}
}
class ExcelMenu extends ExportMenu {
public $showColumnSelector = false;
public $exportFormView = '@vendor/kartik-v/yii2-export/views/_form';
public $exportColumnsView = '@vendor/kartik-v/yii2-export/views/_columns';
function run() {
// We need this because this is a widget within a widget
// Thus there has been an extra ob_start()
$download = !empty($_POST) &&
!empty($_POST[$this->exportRequestParam]) &&
$_POST[$this->exportRequestParam];
if ($download) {
ob_end_clean();
}
return parent::run();
}
}