forked from kartik-v/yii2-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerialColumn.php
executable file
·173 lines (153 loc) · 5.96 KB
/
SerialColumn.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 3.1.6
*/
namespace kartik\grid;
use Closure;
use yii\grid\SerialColumn as YiiSerialColumn;
use yii\helpers\Html;
/**
* A SerialColumn displays a column of row numbers (1-based) and extends the [[YiiSerialColumn]] with various
* enhancements.
*
* To add a SerialColumn to the gridview, add it to the [[GridView::columns|columns]] configuration as follows:
*
* ```php
* 'columns' => [
* // ...
* [
* 'class' => SerialColumn::className(),
* // you may configure additional properties here
* ],
* ]
* ```
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.0
*/
class SerialColumn extends YiiSerialColumn
{
use ColumnTrait;
/**
* @var boolean whether the column is hidden from display. This is different than the `visible` property, in the
* sense, that the column is rendered, but hidden from display. This will allow you to still export the column
* using the export function.
*/
public $hidden;
/**
* @var boolean|array whether the column is hidden in export output. If set to boolean `true`, it will hide the column
* for all export formats. If set as an array, it will accept the list of GridView export `formats` and hide
* output only for them.
*/
public $hiddenFromExport = false;
/**
* @var string the horizontal alignment of each column. Should be one of [[GridView::ALIGN_LEFT]],
* [[GridView::ALIGN_RIGHT]], or [[GridView::ALIGN_CENTER]].
*/
public $hAlign = GridView::ALIGN_CENTER;
/**
* @var string the vertical alignment of each column. Should be one of [[GridView::ALIGN_TOP]],
* [[GridView::ALIGN_BOTTOM]], or [[GridView::ALIGN_MIDDLE]].
*/
public $vAlign = GridView::ALIGN_MIDDLE;
/**
* @var boolean whether to force no wrapping on all table cells in the column
* @see http://www.w3schools.com/cssref/pr_text_white-space.asp
*/
public $noWrap = false;
/**
* @var string the width of each column (matches the CSS width property).
* @see http://www.w3schools.com/cssref/pr_dim_width.asp
*/
public $width = '50px';
/**
* @var boolean|string|Closure the page summary that is displayed above the footer. You can set it to one of the
* following:
* - `false`: the summary will not be displayed.
* - `true`: the page summary for the column will be calculated and displayed using the
* [[pageSummaryFunc]] setting.
* - `string`: will be displayed as is.
* - `Closure`: you can set it to an anonymous function with the following signature:
*
* ```php
* // example 1
* function ($summary, $data, $widget) { return 'Count is ' . $summary; }
* // example 2
* function ($summary, $data, $widget) { return 'Range ' . min($data) . ' to ' . max($data); }
* ```
*
* where:
*
* - the `$summary` variable will be replaced with the calculated summary using the `summaryFunc` setting.
* - the `$data` variable will contain array of the selected page rows for the column.
*/
public $pageSummary = false;
/**
* @var string|Closure the summary function that will be used to calculate the page summary for the column. If
* setting as `Closure`, you can set it to an anonymous function with the following signature:
*
* ```php
* function ($data)
* ```
*
* - the `$data` variable will contain array of the selected page rows for the column.
*/
public $pageSummaryFunc = GridView::F_SUM;
/**
* @var array HTML attributes for the page summary cell. The following special attributes are available:
* - `prepend`: _string_, a prefix string that will be prepended before the pageSummary content
* - `append`: _string_, a suffix string that will be appended after the pageSummary content
*/
public $pageSummaryOptions = [];
/**
* @var boolean whether to just hide the page summary display but still calculate the summary based on
* [[pageSummary]] settings
*/
public $hidePageSummary = false;
/**
* @var boolean whether to merge the header title row and the filter row This will not render the filter for the
* column and can be used when `filter` is set to `false`. Defaults to `false`. This is only applicable when
* [[GridView::filterPosition]] for the grid is set to [[GridView::FILTER_POS_BODY]].
*/
public $mergeHeader = true;
/**
* @var string|array in which format should the value of each data model be displayed as (e.g. `"raw"`, `"text"`,
* `"html"`, `['date', 'php:Y-m-d']`). Supported formats are determined by the
* [[GridView::formatter|formatter]] used by the [[GridView]]. Default format is "text" which will format the
* value as an HTML-encoded plain text when [[\yii\i18n\Formatter]] is used as the
* [[GridView::$formatter|formatter]] of the GridView.
*/
public $format = 'text';
/**
* @var string the cell format for EXCEL exported content.
* @see http://cosicimiento.blogspot.in/2008/11/styling-excel-cells-with-mso-number.html
*/
public $xlFormat;
/**
* @var array collection of row data for the column for the current page
*/
protected $_rows = [];
/**
* @inheritdoc
*/
public function init()
{
$this->parseFormat();
$this->parseVisibility();
parent::init();
$this->setPageRows();
}
/**
* @inheritdoc
*/
public function renderDataCell($model, $key, $index)
{
$options = $this->fetchContentOptions($model, $key, $index);
$this->parseExcelFormats($options, $model, $key, $index);
$out = $this->grid->formatter->format($this->renderDataCellContent($model, $key, $index), $this->format);
return Html::tag('td', $out, $options);
}
}