-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJexcel.php
executable file
·44 lines (38 loc) · 1.22 KB
/
Jexcel.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
<?php
// +----------------------------------------------------------------------
// | jexcel
// +----------------------------------------------------------------------
// | User: Lengnuan <[email protected]>
// +----------------------------------------------------------------------
// | Date: 2019年12月30日
// +----------------------------------------------------------------------
namespace lengnuan\jexcel;
use lengnuan\jexcel\JexcelAsset;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
class Jexcel extends Widget
{
public $options = [];
public function init()
{
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
}
public function run()
{
echo Html::tag('div', '', $this->options);
$this->registerClientScript();
}
protected function registerClientScript()
{
$id = $this->options['id'];
unset($this->options['id']);
$view = $this->getView();
$options = !empty($this->options) ? Json::encode($this->options) : '{}';
JexcelAsset::register($view);
$js = "var jexcel_table = jexcel(document.getElementById(\"{$id}\"), {$options});";
$view->registerJs($js);
}
}