-
Notifications
You must be signed in to change notification settings - Fork 7
/
Column.php
93 lines (87 loc) · 1.7 KB
/
Column.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
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace mdm\widgets;
use Yii;
use yii\helpers\Html;
use yii\base\Model;
/**
* Description of Column
*
* @author Misbahul D Munir <[email protected]>
* @since 1.0
*/
class Column extends BaseObect
{
/**
* @var GridInput
*/
public $grid;
/**
*
* @var string|\Closure
*/
public $value;
/**
*
* @var string header text
*/
public $header;
/**
*
* @var string footer text
*/
public $footer;
/**
*
* @var array
*/
public $headerOptions = [];
/**
*
* @var array
*/
public $contentOptions = [];
/**
*
* @var array
*/
public $footerOptions = [];
/**
* @var string
*/
public $format;
/**
* Render header cell
* @return string
*/
public function renderHeaderCell()
{
return Html::tag('th', $this->header, $this->headerOptions);
}
/**
* Render footer cell
* @return string
*/
public function renderFooterCell()
{
return Html::tag('td', $this->footer, $this->footerOptions);
}
/**
* Render data cell
* @param Model $model model for cell
* @param string $key
* @param integer $index
* @return string
*/
public function renderDataCell($model, $key, $index)
{
if (is_callable($this->value)) {
$value = call_user_func($this->value, $model, $key, $index);
} else {
$value = $this->value;
}
if ($this->format !== null) {
$value = Yii::$app->getFormatter()->format($value, $this->format);
}
return Html::tag('td', $value, $this->contentOptions);
}
}