Содержание
- 1 Property Details
- 2 Method Details
- 3 Method Details
- 4 ListView ¶
- 5 Property Details
- 6 Формат данных в столбцах GridView
- 7 DetailView ¶
- 8 Отображение управляющих кнопок в GridView
- 9 Method Details
- 10 Property Details
- 11 Method Details
- 12 Method Details
- 13 Property Details
- 14 ListView #
- 15 Method Details
- 16 Method Details
- 17 Method Details
- 18 Property Details
Property Details
$content public property
This is a callable that will be used to generate the content of each cell. The signature of the function should be the following: . Where , , and refer to the model, key and index of the row currently being rendered and is a reference to the yii\grid\Column object.
public callable = null
$contentOptions public property
The HTML attributes for the data cell tag. This can either be an array of attributes or an anonymous function (Closure) that returns such an array. The signature of the function should be the following: . Where , , and refer to the model, key and index of the row currently being rendered and is a reference to the yii\grid\Column object. A function may be used to assign different attributes to different rows based on the data in that row.
See also for details on how attributes are being rendered.
public array|Closure = []
$filterOptions public property
The HTML attributes for the filter cell tag.
See also for details on how attributes are being rendered.
public array = []
$footer public property
The footer cell content. Note that it will not be HTML-encoded.
public string = null
$footerOptions public property
The HTML attributes for the footer cell tag.
See also for details on how attributes are being rendered.
public array = []
$grid public property
The grid view object that owns this column.
public yii\grid\GridView = null
$header public property
The header cell content. Note that it will not be HTML-encoded.
public string = null
$headerOptions public property
The HTML attributes for the header cell tag.
See also for details on how attributes are being rendered.
public array = []
$options public property
The HTML attributes for the column group tag.
See also for details on how attributes are being rendered.
public array = []
$visible public property
Whether this column is visible. Defaults to true.
public boolean = true
Method Details
createUrl() public method
Creates a URL for the given action and model.
This method is called for each button and each row.
public string ( $action, $model, $key, $index ) | ||
$action | string |
The button name (or action ID) |
$model | yii\db\ActiveRecordInterface |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The current row index |
return | string |
The created URL |
---|
init() public method
{@inheritdoc}
public void ( ) |
initDefaultButton() protected method (available since version 2.0.11)
Initializes the default button rendering callback for single button.
protected void ( $name, $iconName, $additionalOptions = [] ) | ||
$name | string |
Button name as it’s written in template |
$iconName | string |
The part of Bootstrap glyphicon class that makes it unique |
$additionalOptions | array |
Array of additional options |
initDefaultButtons() protected method
Initializes the default button rendering callbacks.
protected void ( ) |
renderDataCellContent() protected method
{@inheritdoc}
protected void ( $model, $key, $index ) | ||
$model | ||
$key | ||
$index |
Method Details
createUrl() public method
Creates a URL for the given action and model.
This method is called for each button and each row.
public string ( $action, $model, $key, $index ) | ||
$action | string |
The button name (or action ID) |
$model | yii\db\ActiveRecordInterface |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The current row index |
return | string |
The created URL |
---|
init() public method
{@inheritdoc}
public void ( ) |
initDefaultButton() protected method (available since version 2.0.11)
Initializes the default button rendering callback for single button.
protected void ( $name, $iconName, $additionalOptions = [] ) | ||
$name | string |
Button name as it’s written in template |
$iconName | string |
The part of Bootstrap glyphicon class that makes it unique |
$additionalOptions | array |
Array of additional options |
initDefaultButtons() protected method
Initializes the default button rendering callbacks.
protected void ( ) |
renderDataCellContent() protected method
{@inheritdoc}
protected void ( $model, $key, $index ) | ||
$model | ||
$key | ||
$index |
ListView ¶
The ListView widget is used to display data from a data provider. Each data model is rendered using the specified . Since it provides features such as pagination, sorting and filtering out of the box, it is handy both to display information to end user and to create data managing UI.
A typical usage is as follows:
The view file could contain the following:
In the view file above, the current data model is available as . Additionally the following variables are available:
- : mixed, the key value associated with the data item.
- : integer, the zero-based index of the data item in the items array returned by the data provider.
- : ListView, this widget instance.
If you need to pass additional data to each view, you can use the property to pass key value pairs like the following:
These are then also available as variables in the view.
Property Details
$buttonOptions public property (available since version 2.0.4)
Html options to be applied to the .
public array = []
$buttons public property
Button rendering callbacks. The array keys are the button names (without curly brackets), and the values are the corresponding button rendering callbacks. The callbacks should use the following signature:
where is the URL that the column creates for the button, is the model object being rendered for the current row, and is the key of the model in the data provider array.
You can add further conditions to the button, for example only display it, when the model is editable (here assuming you have a status field that indicates that):
public array = []
$controller public property
The ID of the controller that should handle the actions specified here. If not set, it will use the currently active controller. This property is mainly used by to create URLs for different actions. The value of this property will be prefixed to each action name to form the route of the action.
public string = null
$headerOptions public property
The HTML attributes for the header cell tag.
public array = [‘class’ => ‘action-column’
$template public property
The template used for composing each cell in the action column. Tokens enclosed within curly brackets are treated as controller action IDs (also called button names in the context of action column). They will be replaced by the corresponding button rendering callbacks specified in . For example, the token will be replaced by the result of the callback . If a callback cannot be found, the token will be replaced with an empty string.
As an example, to only have the view, and update button you can add the ActionColumn to your GridView columns as follows:
See also .
public string = ‘{view} {update} {delete}’
$urlCreator public property
A callback that creates a button URL using the specified model information. The signature of the callback should be the same as that of Since 2.0.10 it can accept additional parameter, which refers to the column instance itself:
If this property is not set, button URLs will be created using .
public callable = null
$visibleButtons public property (available since version 2.0.7)
Visibility conditions for each button. The array keys are the button names (without curly brackets), and the values are the boolean true/false or the anonymous function. When the button name is not specified in this array it will be shown by default. The callbacks must use the following signature:
Or you can pass a boolean value:
public array = []
Формат данных в столбцах GridView
Для установки своих атрибутов ячейкам таблицы GridView в Yii 2.0, достаточно указать их в параметре contentOptions. Атрибуты могут быть определены как массивом, так и анонимной функцией function ($model, $key, $index, $column), которая может вычислять и возвращать массив атрибутов, таких как class, style, data-key и других.
<?= GridView::widget(, ... // Один вариант ; }, 'content'=>function($data){ return "value"; } ], // Другой вариант , 'content'=>function($data){ return "value"; } ], ... , ], ]); ?>
Сокращенный формат
Yii 2.0 GridView позволяет сократить код настройки поля до вида ‘attribute:format:label’, где attribute — данные из модели, format — шаблон вывода данных (‘raw’ , ‘text’ , ‘html’ , ‘image’, ‘datetime’, ‘time’, ‘date’, и другие), label — заголовок столбца. В итоге, код
'columns' => , [ 'class' => DataColumn::className(), // Не обязательно 'attribute' => 'name', 'format' => 'text', 'label' => 'Name', ], , ]
можно сократить до
'columns' => , 'name:text:Name', , ]
Класс DataColumn::className() присваивается автоматически, если он не указан. Формат данных обрабатывается formatter, используемым GridView. По-умолчанию это yii\i18n\Formatter.
Картинка в Yii 2.0 GridView
Отобразить картинку в GridView можно несколькими способами:
Самый простой: указать тип поля после двоеточия ‘categoryImagePath:image’. Второй вариант — расширенная настройка поля.
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ... // Простой вариант. Автоматическое формирование изображения 'category_image:image', // Второй вариант. Формирование изображения и его параметров через анонимную функцию ); }, ], ... ], ]); ?>
Ссылка в GridView
Настроим поле для вывода ссылки из модели.
... ); } ], ...
Данные из связанных моделей в GridView
Связанные данные выводятся аналогично данным самой модели.
// Простой вариант, но без возможности сортировки по полю 'parent.name', // Вариант с возможностью сортировки по полю [ 'attribute'=>'parent_id', 'label'=>'Родительская категория', 'format'=>'text', // Возможные варианты: raw, html 'content'=>function($data){ return $data->getParentName(); }, 'filter' => Category::getParentsList() ],
В модели Category описаны соответствующие методы.
public function getParent() { return $this->hasOne(Category::className(), ); } public function getParentName() { $parent = $this->parent; return $parent ? $parent->name : ''; }
Вывод даты и времени в GridView
Отобразить данные в формате можно либо прямым указанием типа данных для вывода ‘created_at:datetime’, ‘created_at:date’, ‘created_at:time’ или с использованием расширенного варианта.
// Самый простой вариант. Доступные модификаторы - date:datetime:time 'created_at:time', // Расширенный вариант с использованием стандартных шаблонов вывода даты/времени [ 'attribute'=>'created_at', 'label'=>'Создано', 'format'=>'datetime', // Доступные модификаторы - date:datetime:time 'headerOptions' => , ], // Вариант с явным указанием формата вывода даты/времени , 'options' => ],
DropDownList в фильтре GridView Yii 2.0
По-умолчанию, GridView использует текстовый фильтр. Для создания фильтра в виде выпадающего меню, достаточно указать массив значений, по которым будет производиться фильтрация в параметре filter. Сортировка и фильтр данных по связанным полям уже описана в соответствующей заметке.
Массив можно задать вручную или получать из модели.
<?= GridView::widget(, ... , ... , ], ]); ?>
Второй вариант
<?= GridView::widget(, ... [ 'attribute'=>'parent_id', 'label'=>'Родительская категория', 'format'=>'text', // Возможные варианты: raw, html 'content'=>function($data){ return $data->getParentName(); }, 'filter' => Category::getParentsList() ], ... , ], ]); ?>
Получение списка категорий, имеющих дочерние, организовано в модели.
public static function getParentsList() { // Выбираем только те категории, у которых есть дочерние категории $parents = Category::find() ->select() ->join('JOIN', 'category c', 'category.parent_id = c.id') ->distinct(true) ->all(); return ArrayHelper::map($parents, 'id', 'name'); }
DetailView ¶
The DetailView widget displays the details of a single data .
It is best used for displaying a model in a regular format (e.g. each model attribute is displayed as a row in a table). The model can be either an instance or subclass of yii\base\Model such as an active record or an associative array.
DetailView uses the property to determine which model attributes should be displayed and how they should be formatted. See the formatter section for available formatting options.
A typical usage of DetailView is as follows:
Remember that unlike yii\widgets\GridView which processes a set of models, DetailView processes just one. So most of the time there is no need for using closure since is the only one model for display and available in view as a variable.
However some cases can make using of closure useful. For example when is specified and you want to prevent calculations in case it evaluates to :
Отображение управляющих кнопок в GridView
Настройка вывода и вида кнопок в GridView осуществляется указанием класса, шаблона и других параметров столбца.
<?= GridView::widget(, ... , 'template' => '{view} {update} {delete}{link}', ], ], ]); ?>
Вывести нестандартные кнопки можно при помощи анонимных функций.
<?= GridView::widget(, ... [ 'class' => 'yii\grid\ActionColumn', 'template' => '{view} {update} {delete} {link}', 'buttons' => [ 'update' => function ($url,$model) { return Html::a( '<span class="glyphicon glyphicon-screenshot"></span>', $url); }, 'link' => function ($url,$model,$key) { return Html::a('Действие', $url); }, ], ], ], ]); ?>
Method Details
getHeaderCellLabel() protected method (available since version 2.0.8)
Returns header cell label.
This method may be overridden to customize the label of the header cell.
protected string ( ) | ||
return | string |
Label |
---|
renderDataCell() public method
Renders a data cell.
public string ( $model, $key, $index ) | ||
$model | mixed |
The data model being rendered |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data item among the item array returned by . |
return | string |
The rendering result |
---|
renderDataCellContent() protected method
Renders the data cell content.
protected string ( $model, $key, $index ) | ||
$model | mixed |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data model among the models array returned by . |
return | string |
The rendering result |
---|
renderFilterCell() public method
Renders the filter cell.
public void ( ) |
renderFilterCellContent() protected method
Renders the filter cell content.
The default implementation simply renders a space. This method may be overridden to customize the rendering of the filter cell (if any).
protected string ( ) | ||
return | string |
The rendering result |
---|
renderFooterCell() public method
Renders the footer cell.
public void ( ) |
renderFooterCellContent() protected method
Renders the footer cell content.
The default implementation simply renders . This method may be overridden to customize the rendering of the footer cell.
protected string ( ) | ||
return | string |
The rendering result |
---|
renderHeaderCell() public method
Renders the header cell.
public void ( ) |
renderHeaderCellContent() protected method
Renders the header cell content.
The default implementation simply renders . This method may be overridden to customize the rendering of the header cell.
protected string ( ) | ||
return | string |
The rendering result |
---|
Property Details
$attribute public property
The attribute name associated with this column. When neither nor is specified, the value of the specified attribute will be retrieved from each data model and displayed.
Also, if is not specified, the label associated with the attribute will be displayed.
public string = null
$enableSorting public property
Whether to allow sorting by this column. If true and is found in the sort definition of , then the header cell of this column will contain a link that may trigger the sorting when being clicked.
public boolean = true
$encodeLabel public property (available since version 2.0.1)
Whether the header label should be HTML-encoded.
See also .
public boolean = true
$filter public property
The HTML code representing a filter input (e.g. a text field, a dropdown list) that is used for this data column. This property is effective only when is set.
- If this property is not set, a text field will be generated as the filter input with attributes defined with . See for details on how an active input tag is generated.
- If this property is an array, a dropdown list will be generated that uses this property value as the list options.
- If you don’t want a filter for this data column, set this value to be false.
public string|array|null|false = null
$filterInputOptions public property
The HTML attributes for the filter input fields. This property is used in combination with the property. When is not set or is an array, this property will be used to render the HTML attributes for the generated filter input fields.
Empty in the default value ensures that id would not be obtained from the model attribute thus providing better performance.
See also for details on how attributes are being rendered.
public array = [‘class’ => ‘form-control’, ‘id’ => null
$format public property
In which format should the value of each data model be displayed as (e.g. , , , ). Supported formats are determined by the used by the yii\grid\GridView. Default format is «text» which will format the value as an HTML-encoded plain text when yii\i18n\Formatter is used as the of the GridView.
See also .
public string|array|Closure = ‘text’
$label public property
Label to be displayed in the and also to be used as the sorting link label when sorting is enabled for this column. If it is not set and the models provided by the GridViews data provider are instances of yii\db\ActiveRecord, the label will be determined using . Otherwise will be used to get a label.
public string = null
$sortLinkOptions public property
The HTML attributes for the link tag in the header cell generated by when sorting is enabled for this column.
See also for details on how attributes are being rendered.
public array = []
$value public property
An anonymous function or a string that is used to determine the value to display in the current column.
If this is an anonymous function, it will be called for each row and the return value will be used as the value to display for every data model. The signature of this function should be: . Where , , and refer to the model, key and index of the row currently being rendered and is a reference to the yii\grid\DataColumn object.
You may also set this property to a string representing the attribute name to be displayed in this column. This can be used when the attribute to be displayed is different from the that is used for sorting and filtering.
If this is not set, will be used to obtain the value, where is the value of .
public string|Closure = null
Method Details
getHeaderCellLabel() protected method (available since version 2.0.8)
Returns header cell label.
This method may be overridden to customize the label of the header cell.
protected string ( ) | ||
return | string |
Label |
---|
renderDataCell() public method
Renders a data cell.
public string ( $model, $key, $index ) | ||
$model | mixed |
The data model being rendered |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data item among the item array returned by . |
return | string |
The rendering result |
---|
renderDataCellContent() protected method
Renders the data cell content.
protected string ( $model, $key, $index ) | ||
$model | mixed |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data model among the models array returned by . |
return | string |
The rendering result |
---|
renderFilterCell() public method
Renders the filter cell.
public void ( ) |
renderFilterCellContent() protected method
Renders the filter cell content.
The default implementation simply renders a space. This method may be overridden to customize the rendering of the filter cell (if any).
protected string ( ) | ||
return | string |
The rendering result |
---|
renderFooterCell() public method
Renders the footer cell.
public void ( ) |
renderFooterCellContent() protected method
Renders the footer cell content.
The default implementation simply renders . This method may be overridden to customize the rendering of the footer cell.
protected string ( ) | ||
return | string |
The rendering result |
---|
renderHeaderCell() public method
Renders the header cell.
public void ( ) |
renderHeaderCellContent() protected method
Renders the header cell content.
The default implementation simply renders . This method may be overridden to customize the rendering of the header cell.
protected string ( ) | ||
return | string |
The rendering result |
---|
Method Details
createUrl() public method
Creates a URL for the given action and model.
This method is called for each button and each row.
public string ( $action, $model, $key, $index ) | ||
$action | string |
The button name (or action ID) |
$model | yii\db\ActiveRecordInterface |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The current row index |
return | string |
The created URL |
---|
init() public method
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
public void ( ) |
initDefaultButton() protected method (available since version 2.0.11)
Initializes the default button rendering callback for single button.
protected void ( $name, $iconName, $additionalOptions = [] ) | ||
$name | string |
Button name as it’s written in template |
$iconName | string |
The part of Bootstrap glyphicon class that makes it unique |
$additionalOptions | array |
Array of additional options |
initDefaultButtons() protected method
Initializes the default button rendering callbacks.
protected void ( ) |
renderDataCellContent() protected method
Renders the data cell content.
protected string ( $model, $key, $index ) | ||
$model | mixed |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data model among the models array returned by . |
return | string |
The rendering result |
---|
Property Details
$buttonOptions public property (available since version 2.0.4)
Html options to be applied to the .
public array = []
$buttons public property
Button rendering callbacks. The array keys are the button names (without curly brackets), and the values are the corresponding button rendering callbacks. The callbacks should use the following signature:
where is the URL that the column creates for the button, is the model object being rendered for the current row, and is the key of the model in the data provider array.
You can add further conditions to the button, for example only display it, when the model is editable (here assuming you have a status field that indicates that):
public array = []
$controller public property
The ID of the controller that should handle the actions specified here. If not set, it will use the currently active controller. This property is mainly used by to create URLs for different actions. The value of this property will be prefixed to each action name to form the route of the action.
public string = null
$headerOptions public property
public = [‘class’ => ‘action-column’
$template public property
The template used for composing each cell in the action column. Tokens enclosed within curly brackets are treated as controller action IDs (also called button names in the context of action column). They will be replaced by the corresponding button rendering callbacks specified in . For example, the token will be replaced by the result of the callback . If a callback cannot be found, the token will be replaced with an empty string.
As an example, to only have the view, and update button you can add the ActionColumn to your GridView columns as follows:
See also .
public string = ‘{view} {update} {delete}’
$urlCreator public property
A callback that creates a button URL using the specified model information. The signature of the callback should be the same as that of Since 2.0.10 it can accept additional parameter, which refers to the column instance itself:
If this property is not set, button URLs will be created using .
public callable = null
$visibleButtons public property (available since version 2.0.7)
Visibility conditions for each button. The array keys are the button names (without curly brackets), and the values are the boolean true/false or the anonymous function. When the button name is not specified in this array it will be shown by default. The callbacks must use the following signature:
Or you can pass a boolean value:
public array = []
ListView #
Виджет ListView использует для отображения информации провайдера данных. Каждая модель отображается, используя определённый . Поскольку провайдер включает в себя разбивку на страницы, сортировку и фильтрацию, то его использование удобно для отображения информации конечному пользователю и создания интерфейса управления данными.
Обычное использование сводится к следующему коду:
файл вид, который может содержать следующее:
В вышеописанном коде текущая модель доступна как . Кроме этого доступны дополнительные переменные:
- : mixed, значение ключа в соответствии с данными.
- : integer, индекс элемента данных в массиве элементов, возвращенных поставщику данных, который начинается с 0.
- : ListView, это экземпляр виджета.
Если необходимо послать дополнительные данные в каждый вид, то можно использовать свойство как ключ-значение, например:
Они также станут доступны в виде в качестве переменных.
Method Details
createDataColumn() protected method
Creates a yii\grid\DataColumn object based on a string in the format of «attribute:format:label».
protected yii\grid\DataColumn ( $text ) | ||
$text | string |
The column specification string |
return | yii\grid\DataColumn |
The column instance |
---|---|---|
throws | yii\base\InvalidConfigException |
if the column specification is invalid |
getClientOptions() protected method
Returns the options for the grid view JS widget.
protected array ( ) | ||
return | array |
The options |
---|
guessColumns() protected method
This function tries to guess the columns to show from the given data if are not explicitly specified.
protected void ( ) |
init() public method
Initializes the grid view.
This method will initialize required property values and instantiate objects.
public void ( ) |
initColumns() protected method
Creates column objects and initializes them.
protected void ( ) |
renderCaption() public method
Renders the caption element.
public boolean|string ( ) | ||
return | boolean|string |
The rendered caption element or if no caption element should be rendered. |
---|
renderColumnGroup() public method
Renders the column group HTML.
public boolean|string ( ) | ||
return | boolean|string |
The column group HTML or if no column group should be rendered. |
---|
renderErrors() public method
Renders validator errors of filter model.
public string ( ) | ||
return | string |
The rendering result. |
---|
renderFilters() public method
Renders the filter.
public string ( ) | ||
return | string |
The rendering result. |
---|
renderItems() public method
Renders the data models for the grid view.
public string ( ) | ||
return | string |
The HTML code of table |
---|
renderSection() public method
Renders a section of the specified name.
If the named section is not supported, false will be returned.
public string|boolean ( $name ) | ||
$name | string |
The section name, e.g., , . |
return | string|boolean |
The rendering result of the section, or false if the named section is not supported. |
---|
renderTableBody() public method
Renders the table body.
public string ( ) | ||
return | string |
The rendering result. |
---|
renderTableFooter() public method
Renders the table footer.
public string ( ) | ||
return | string |
The rendering result. |
---|
renderTableHeader() public method
Renders the table header.
public string ( ) | ||
return | string |
The rendering result. |
---|
renderTableRow() public method
Renders a table row with the given data model and key.
public string ( $model, $key, $index ) | ||
$model | mixed |
The data model to be rendered |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data model among the model array returned by . |
return | string |
The rendering result |
---|
run() public method
Runs the widget.
public void ( ) |
Method Details
getHeaderCellLabel() protected method (available since version 2.0.8)
Returns header cell label.
This method may be overridden to customize the label of the header cell.
protected string ( ) | ||
return | string |
Label |
---|
renderDataCell() public method
Renders a data cell.
public string ( $model, $key, $index ) | ||
$model | mixed |
The data model being rendered |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data item among the item array returned by . |
return | string |
The rendering result |
---|
renderDataCellContent() protected method
Renders the data cell content.
protected string ( $model, $key, $index ) | ||
$model | mixed |
The data model |
$key | mixed |
The key associated with the data model |
$index | integer |
The zero-based index of the data model among the models array returned by . |
return | string |
The rendering result |
---|
renderFilterCell() public method
Renders the filter cell.
public void ( ) |
renderFilterCellContent() protected method
Renders the filter cell content.
The default implementation simply renders a space. This method may be overridden to customize the rendering of the filter cell (if any).
protected string ( ) | ||
return | string |
The rendering result |
---|
renderFooterCell() public method
Renders the footer cell.
public void ( ) |
renderFooterCellContent() protected method
Renders the footer cell content.
The default implementation simply renders . This method may be overridden to customize the rendering of the footer cell.
protected string ( ) | ||
return | string |
The rendering result |
---|
renderHeaderCell() public method
Renders the header cell.
public void ( ) |
renderHeaderCellContent() protected method
Renders the header cell content.
The default implementation simply renders . This method may be overridden to customize the rendering of the header cell.
protected string ( ) | ||
return | string |
The rendering result |
---|
Method Details
createDataColumn()
method
protected CDataColumn createDataColumn(string $text) | ||
$text | string | the column specification string |
{return} | CDataColumn | the column instance |
Source Code: ()
Creates a CDataColumn based on a shortcut column specification string.
getFormatter()
method
public CFormatter getFormatter() | ||
{return} | CFormatter | the formatter instance. Defaults to the ‘format’ application component. |
Source Code: ()
getHasFooter()
method
public boolean getHasFooter() | ||
{return} | boolean | whether the table should render a footer. This is true if any of the has a true value. |
Source Code: ()
init()
method
public void init() |
Source Code: ()
Initializes the grid view. This method will initialize required property values and instantiate objects.
initColumns()
method
protected void initColumns() |
Source Code: ()
Creates column objects and initializes them.
registerClientScript()
method
public void registerClientScript() |
Source Code: ()
Registers necessary client scripts.
renderDataCell()
method (available since v1.1.16)
protected void renderDataCell(CGridColumn $column, integer $row) | ||
$column | CGridColumn | The Column instance to |
$row | integer |
Source Code: ()
A seam for people extending CGridView to be able to hook onto the data cell rendering process.
By overriding only this method we will not need to copypaste and modify the whole entirety of `renderTableRow`. Or override `renderDataCell()` method of all possible CGridColumn descendants.
renderFilter()
method (available since v1.1.1)
public void renderFilter() |
Source Code: ()
Renders the filter.
renderItems()
method
public void renderItems() |
Source Code: ()
Renders the data items for the grid view.
renderTableBody()
method
public void renderTableBody() |
Source Code: ()
Renders the table body.
renderTableFooter()
method
public void renderTableFooter() |
Source Code: ()
Renders the table footer.
renderTableHeader()
method
public void renderTableHeader() |
Source Code: ()
Renders the table header.
renderTableRow()
method
public void renderTableRow(integer $row) | ||
$row | integer | the row number (zero-based). |
Source Code: ()
Renders a table body row.
setFormatter()
method
public void setFormatter(CFormatter $value) | ||
$value | CFormatter | the formatter instance |
Source Code: ()
Property Details
$content public property
This is a callable that will be used to generate the content of each cell. The signature of the function should be the following: . Where , , and refer to the model, key and index of the row currently being rendered and is a reference to the yii\grid\Column object.
public callable = null
$contentOptions public property
The HTML attributes for the data cell tag. This can either be an array of attributes or an anonymous function (Closure) that returns such an array. The signature of the function should be the following: . Where , , and refer to the model, key and index of the row currently being rendered and is a reference to the yii\grid\Column object. A function may be used to assign different attributes to different rows based on the data in that row.
See also for details on how attributes are being rendered.
public array|Closure = []
$filterOptions public property
The HTML attributes for the filter cell tag.
See also for details on how attributes are being rendered.
public array = []
$footer public property
The footer cell content. Note that it will not be HTML-encoded.
public string = null
$footerOptions public property
The HTML attributes for the footer cell tag.
See also for details on how attributes are being rendered.
public array = []
$grid public property
The grid view object that owns this column.
public yii\grid\GridView = null
$header public property
The header cell content. Note that it will not be HTML-encoded.
public string = null
$headerOptions public property
The HTML attributes for the header cell tag.
See also for details on how attributes are being rendered.
public array = []
$options public property
The HTML attributes for the column group tag.
See also for details on how attributes are being rendered.
public array = []
$visible public property
Whether this column is visible. Defaults to true.
public boolean = true
С этим читают