-
Notifications
You must be signed in to change notification settings - Fork 3
/
FloatThead.php
58 lines (51 loc) · 1.42 KB
/
FloatThead.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
<?php
/**
* @link https://github.com/bluezed/yii2-floatThead
* @copyright Copyright (c) 2015 Thomas Geppert
* @license https://github.com/bluezed/yii2-floatThead/blob/master/LICENSE
*/
namespace bluezed\floatThead;
use yii\helpers\Json;
use yii\base\Widget;
/**
* The yii2-floatThead is a Yii 2 wrapper for the jquery.floatThead
* See more: http://mkoryak.github.io/floatThead/
*
* @author Thomas Geppert <[email protected]>
*/
class FloatThead extends Widget
{
/**
* @var string - ID of the table that floatThead should be applied to
*/
public $tableId;
/**
* @var array - Options that will be passed on to the plugin
*/
public $options = [];
/**
* @var bool - Only registers the assets but will not apply the plugin to any table.
* NOTE: If this is used then the tableId and options have no effect!
*/
public $registerOnly = false;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->registerAssets();
}
/**
* Registers the required assets
*/
public function registerAssets()
{
$view = $this->getView();
FloatTheadAsset::register($view);
if (!$this->registerOnly) {
$options = Json::encode($this->options);
$view->registerJs('$("#'.$this->tableId.'").floatThead(' .$options .');', $view::POS_READY);
}
}
}