Class kartik\grid\DataColumn
Inheritance | kartik\grid\DataColumn » yii\grid\DataColumn » yii\grid\Column » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Uses Traits | kartik\grid\ColumnTrait |
Subclasses | kartik\grid\BooleanColumn, kartik\grid\EditableColumn, kartik\grid\EnumColumn, kartik\grid\ExpandRowColumn, kartik\grid\FormulaColumn |
Available since version | 1.0 |
The DataColumn is the default column type for the kartik\grid\GridView widget and extends the yii\grid\DataColumn with various enhancements.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$attribute | string | The attribute name associated with this column. | yii\grid\DataColumn |
$columnKey | string | An unique identifier for the Column. | kartik\grid\ColumnTrait |
$content | callable | This is a callable that will be used to generate the content of each cell. | yii\grid\Column |
$contentOptions | array|Closure | The HTML attributes for the data cell tag. | yii\grid\Column |
$enableSorting | boolean | Whether to allow sorting by this column. | yii\grid\DataColumn |
$encodeLabel | boolean | Whether the header label should be HTML-encoded. | yii\grid\DataColumn |
$exportMenuHeaderStyle | array | Configuration for the \kartik\export\ExportMenu column header cell style that will be utilized by
\PhpOffice\PhpSpreadsheet\Style\Style::applyFromArray() . |
kartik\grid\DataColumn |
$exportMenuStyle | array|Closure | Configuration for the \kartik\export\ExportMenu column cell style that will be utilized by
\PhpOffice\PhpSpreadsheet\Style\Style::applyFromArray() . |
kartik\grid\DataColumn |
$filter | string|array|null|false | The HTML code representing a filter input (e.g. a text field, a dropdown list) that is used for this data column. | yii\grid\DataColumn |
$filterAttribute | string|null | The attribute name of the yii\grid\GridView::$filterModel associated with this column. | yii\grid\DataColumn |
$filterInputOptions | array | The HTML attributes for the filter input fields. | yii\grid\DataColumn |
$filterOptions | array | The HTML attributes for the filter cell tag. | yii\grid\Column |
$filterType | string | The filter input type for each filter input. | kartik\grid\DataColumn |
$filterWidgetOptions | array | The options/settings for the filter widget. | kartik\grid\DataColumn |
$footer | string | The footer cell content. | yii\grid\Column |
$footerOptions | array | The HTML attributes for the footer cell tag. | yii\grid\Column |
$format | string|array|Closure | In which format should the value of each data model be displayed as (e.g. "raw" , "text" , "html" ,
['date', 'php:Y-m-d'] ). |
yii\grid\DataColumn |
$grid | yii\grid\GridView | The grid view object that owns this column. | yii\grid\Column |
$group | boolean | Whether to group grid data by this column. | kartik\grid\DataColumn |
$groupEvenCssClass | string|\kartik\grid\Closure, | The even group css class. | kartik\grid\DataColumn |
$groupFooter | array|Closure | Configuration of the group footer which will be displayed as a separate row. | kartik\grid\DataColumn |
$groupHeader | array|Closure | Configuration of the group header which will be displayed as a separate row above the group. | kartik\grid\DataColumn |
$groupOddCssClass | string|\kartik\grid\Closure, | The odd group css class. | kartik\grid\DataColumn |
$groupedRow | boolean|\kartik\grid\Closure, | Whether to add a separate group row for grouping. | kartik\grid\DataColumn |
$hAlign | string | The horizontal alignment of each column. | kartik\grid\ColumnTrait |
$header | string|null | The header cell content. | yii\grid\Column |
$headerOptions | array | The HTML attributes for the header cell tag. | yii\grid\Column |
$hidePageSummary | boolean | Whether to just hide the page summary display but still calculate the summary based on $pageSummary settings | kartik\grid\ColumnTrait |
$label | string|null | Label to be displayed in the header cell and also to be used as the sorting link label when sorting is enabled for this column. | yii\grid\DataColumn |
$mergeHeader | boolean | Whether to merge the header title row and the filter row. | kartik\grid\ColumnTrait |
$noWrap | boolean | Whether to force no wrapping on all table cells in the column | kartik\grid\ColumnTrait |
$options | array | The HTML attributes for the column group tag. | yii\grid\Column |
$pageSummary | boolean|string|Closure | The page summary that is displayed above the footer. | kartik\grid\ColumnTrait |
$pageSummaryFormat | string|array|Closure | In which format should the value of each data model be displayed as (e.g. "raw" , "text" , "html" ,
['date', 'php:Y-m-d'] ). |
kartik\grid\ColumnTrait |
$pageSummaryFunc | string|Closure | The summary function that will be used to calculate the page summary for the column. | kartik\grid\ColumnTrait |
$pageSummaryOptions | array | HTML attributes for the page summary cell. | kartik\grid\ColumnTrait |
$sortLinkOptions | array | The HTML attributes for the link tag in the header cell generated by yii\data\Sort::link() when sorting is enabled for this column. | yii\grid\DataColumn |
$stripTagsFromExport | boolean | Whether to strip HTML tags from the column during export. | kartik\grid\ColumnTrait |
$subGroupOf | integer|Closure | The column index of which this group is a sub group of. | kartik\grid\DataColumn |
$vAlign | string | The vertical alignment of each column. | kartik\grid\ColumnTrait |
$value | string|Closure|null | An anonymous function or a string that is used to determine the value to display in the current column. | yii\grid\DataColumn |
$visible | boolean | Whether this column is visible. | yii\grid\Column |
$width | string | The width of each column (matches the CSS width property). | kartik\grid\ColumnTrait |
$xlFormat | string | The cell format for EXCEL exported content. | kartik\grid\DataColumn |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$_clientScript | string | The internally generated client script to initialize | kartik\grid\ColumnTrait |
$_rows | array | Collection of row data for the column for the current page | kartik\grid\ColumnTrait |
$_view | yii\web\View | The view instance | kartik\grid\ColumnTrait |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\BaseObject |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
getDataCellValue() | Returns the data cell value. | yii\grid\DataColumn |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the object. | kartik\grid\DataColumn |
initColumnSettings() | Initialize column settings | kartik\grid\ColumnTrait |
parseExcelFormats() | Parses Excel Cell Formats for export | kartik\grid\ColumnTrait |
renderDataCell() | Renders a data cell. | kartik\grid\DataColumn |
renderFilterCell() | Renders the filter cell. | kartik\grid\ColumnTrait |
renderFooterCell() | Renders the footer cell. | yii\grid\Column |
renderHeaderCell() | Renders the header cell. | kartik\grid\ColumnTrait |
renderPageSummaryCell() | Renders the page summary cell. | kartik\grid\ColumnTrait |
Protected Methods
Method | Description | Defined By |
---|---|---|
calculateSummary() | Calculates the summary of an input data based on page summary aggregration function. | kartik\grid\ColumnTrait |
checkValidFilters() | Checks if the filter input types are valid | kartik\grid\ColumnTrait |
fetchContentOptions() | Parses and fetches updated content options for grid visibility and format | kartik\grid\ColumnTrait |
getFooterCellContent() | Get the raw footer cell content. | kartik\grid\ColumnTrait |
getHeaderCellLabel() | Returns header cell label. | yii\grid\DataColumn |
getPageSummaryCellContent() | Gets the raw page summary cell content. | kartik\grid\ColumnTrait |
initColumnKey() | Initializes the column key | kartik\grid\ColumnTrait |
initGrouping() | Initializes grid grouping | kartik\grid\ColumnTrait |
initPjax() | Initialize column specific JS functionality whenever pjax request completes | kartik\grid\ColumnTrait |
isValidAlignment() | Check if the alignment provided is valid | kartik\grid\ColumnTrait |
parseFormat() | Parses and formats a grid column | kartik\grid\ColumnTrait |
parseGrouping() | Parses grid grouping and sets data attributes | kartik\grid\ColumnTrait |
parseVal() | Parses a value if Closure and returns the right value | kartik\grid\ColumnTrait |
parseVisibility() | Checks hidden property and hides the column from display |
kartik\grid\ColumnTrait |
renderDataCellContent() | Renders the data cell content. | yii\grid\DataColumn |
renderFilterCellContent() | Renders filter inputs based on the filterType |
kartik\grid\DataColumn |
renderFooterCellContent() | Renders the footer cell content. | yii\grid\Column |
renderHeaderCellContent() | Renders the header cell content. | kartik\grid\DataColumn |
renderPageSummaryCellContent() | Renders the page summary cell content. | kartik\grid\ColumnTrait |
setPageRows() | Store all rows for the column for the current page | kartik\grid\ColumnTrait |
Property Details
Configuration for the \kartik\export\ExportMenu
column header cell style that will be utilized by
\PhpOffice\PhpSpreadsheet\Style\Style::applyFromArray()
. This is applicable when configuring this column
in \kartik\export\ExportMenu
.
'alignment' => ['vertical' => \kartik\grid\GridView::ALIGN_CENTER]
]
Configuration for the \kartik\export\ExportMenu
column cell style that will be utilized by
\PhpOffice\PhpSpreadsheet\Style\Style::applyFromArray()
. This is applicable when configuring this column
in \kartik\export\ExportMenu
. If setup as a Closure, the signature of the function should be: function
($model, $key, $index, $column)
, where $model
, $key
, and $index
refer to the model, key and index of
the row currently being rendered, and $column
is a reference to the kartik\grid\DataColumn object.
'alignment' => ['vertical' => \kartik\grid\GridView::ALIGN_CENTER]
]
The filter input type for each filter input. You can use one of the GridView::FILTER_
constants or
pass any widget classname (extending the Yii Input Widget).
The options/settings for the filter widget. Will be used only if you set filterType
to a widget
classname that exists.
Whether to group grid data by this column. Defaults to false
. Note that your query must sort the
data by this column for it to be effective.
The even group css class. Defaults to 'kv-group-even'. If setup as a Closure, the signature
of the function should be: function ($model, $key, $index, $column)
, where $model
, $key
, and $index
refer to the model, key and index of the row currently being rendered, and $column
is a reference to the
kartik\grid\DataColumn object.
Configuration of the group footer which will be displayed as a separate row. If this is
empty, no group footer will be rendered. If setup as a Closure, the signature of the function should be:
function ($model, $key, $index, $column)
, where $model
, $key
, and $index
refer to the model, key and
index of the row currently being rendered, and $column
is a reference to the kartik\grid\DataColumn object.
$column
is a reference to the kartik\grid\DataColumn object. The following array keys are recognized:
mergeColumns
:array
, of columns that will be merged asfrom, to
pairs. For example if you need to merge column numbers 0 to 2 and column numbers 3 to 6, you can set this as:[ [0, 2], [3, 6] ]
content
:array
, footer content for each column. You must set this as$key => $value
, where$key
is the 0 based index for the column, and$value
is the content to display for the column. The$value
can take in special function names to summarize values for the column. If set to one ofGridView::F_COUNT
,GridView::F_SUM
,GridView::F_AVG
,GridView::F_MAX
,GridView::F_MIN
, the values will be auto summarized. For example:[ 0 => 'Total', 8 => GridView::F_SUM ]
contentFormats
:array
, footer content formats for each column. This is only applicable currently only for number type or a custom type using a javascript callback. You must set this as$key => $value
, where$key
is the 0 based index for the column, and$value
is the format settings for the column. The$value
is a format specification setup as an array containing one or more of the following options:format
: string, whethernumber
orcallback
decimals
: number, number of decimals (for number format only)decPoint
: string, decimals point character (for number format only). Defaults to.
.thousandSep
: string, thousands separator character (for number format only). Defaults to,
.func
: string, the javascript callback function name (for callback format only). This should be set to a globally accessible javascript function name. For example if you set this tocustomCallback
, the function should be of the signature:function customCallback(source, data) { return custom_convert(source, data); }
. The parameters for the callback function that will be passed are:source
: string, the summary column source as set incontent
section if availabledata
:array
, the text values of each of the child columns in this group. An example of setting thecontent
:`
php [ 7 => ['format'=>'callback', 'func'=>'customCallback'] 8 => ['format'=>'number', 'decimals'=>2, 'decPoint'=>'.', 'thousandSep'=>','] ]`
contentOptions
:array
, footer HTML attributes for each column. You must set this as$key => $value
, where$key
is the 0 based index for the column, and$value
is the HTML attributes to apply for the column. The$value
must be an array of HTML attributes for the table column. An example of setting thecontentOptions
:`
php [0 => ['style'=>'font-weight:bold'], 8 => ['style'=>'text-align:right']
]
`
options
:array
, HTML attributes for the group footer row.
Configuration of the group header which will be displayed as a separate row above the group.
If this is empty, no group header will be rendered. If setup as a Closure, the signature of the function
should be: function ($model, $key, $index, $column)
, where $model
, $key
, and $index
refer to the
model, key and index of the row currently being rendered, and $column
is a reference to the kartik\grid\DataColumn
object. The following array keys are recognized:
mergeColumns
:array
, of columns that will be merged asfrom, to
pairs. For example if you need to merge column numbers 0 to 2 and column numbers 3 to 6, you can set this as:[ [0, 2], [3, 6] ]
content
:array
, header content for each column. You must set this as$key => $value
, where$key
is the zero based index for the column, and$value
is the content to display for the column. The$value
can take in special function names to summarize values for the column. If set to one of GridView::F_COUNT, GridView::F_SUM, GridView::F_AVG, GridView::F_MAX, GridView::F_MIN, the values will be auto summarized.contentFormats
:array
, header content formats for each column. This is only applicable currently only for number type or a custom type using a javascript callback. You must set this as$key => $value
, where$key
is the 0 based index for the column, and$value
is the format settings for the column. The$value
is a format specification setup as an array containing one or more of the following options:format
: string, whethernumber
orcallback
decimals
: number, number of decimals (for number format only)decPoint
: string, decimals point character (for number format only). Defaults to.
.thousandSep
: string, thousands separator character (for number format only). Defaults to,
.func
: string, the javascript callback function name (for callback format only). This should be set to a globally accessible javascript function name. For example if you set this tocustomCallback
, the function should be of the signature:function customCallback(source, data) { return custom_convert(source, data);}
. The parameters for the callback function that will be passed are:source
: string, the summary column source as set incontent
section if availabledata
:array
, the text values of each of the child columns in this group. An example of setting thecontent
:`
php [ 7 => ['format'=>'callback', 'func'=>'customCallback'] 8 => ['format'=>'number', 'decimals'=>2, 'decPoint'=>'.', 'thousandSep'=>','] ]`
contentOptions
:array
, header HTML attributes for each column. You must set this as$key => $value
, where$key
is the 0 based index for the column, and$value
is the HTML attributes to apply for the column. The$value
must be an array of HTML attributes for the table column. An example of setting thecontentOptions
:`
php [ 0 => ['style'=>'font-weight:bold'], 8 => ['style'=>'text-align:right'] ]`
options
:array
, HTML attributes for the group header row.
The odd group css class. Defaults to 'kv-group-odd'. If setup as a Closure, the signature
of the function should be: function ($model, $key, $index, $column)
, where $model
, $key
, and $index
refer to the model, key and index of the row currently being rendered, and $column
is a reference to the
kartik\grid\DataColumn object.
Whether to add a separate group row for grouping. This is applicable only when group
property is true
. Defaults to false
. If set to true
, the column will be hidden and its value will be
displayed in a separate row above. The default behavior is to show the grouped content in a separate column
(when this property is false
). If setup as a Closure, the signature of the function should be: function
($model, $key, $index, $column)
, where $model
, $key
, and $index
refer to the model, key and index of
the row currently being rendered, and $column
is a reference to the kartik\grid\DataColumn object.
The column index of which this group is a sub group of. This is validated only if group
is set to true
. If setup as a Closure, the signature of the function should be: function ($model, $key,
$index, $column)
, where $model
, $key
, and $index
refer to the model, key and index of the row
currently being rendered, and $column
is a reference to the kartik\grid\DataColumn object.
The cell format for EXCEL exported content.
See also http://cosicimiento.blogspot.in/2008/11/styling-excel-cells-with-mso-number.html.
Method Details
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
public void init ( ) | ||
throws | yii\base\InvalidConfigException |
---|
Renders a data cell.
public string renderDataCell ( $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 kartik\grid\GridView::$dataProvider. |
return | string | The rendering result |
---|
Renders filter inputs based on the filterType
protected string renderFilterCellContent ( ) | ||
throws | Exception |
---|
Renders the header cell content.
The default implementation simply renders $header. This method may be overridden to customize the rendering of the header cell.
protected string renderHeaderCellContent ( ) | ||
return | string | The rendering result |
---|