Trait kartik\grid\GridViewTrait
Implemented by | kartik\export\ExportMenu, kartik\grid\GridView |
---|---|
Available since version | 1.0 |
The Krajee GridView Trait contains all methods and properties that enhances the Yii2 GridView widget.
See also http://demos.krajee.com/grid.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$afterFooter | array|string | Configuration of additional footer table rows that will be rendered after the default grid footer row. | kartik\grid\GridViewTrait |
$afterHeader | array|string | Configuration of additional header table rows that will be rendered after default grid header row. | kartik\grid\GridViewTrait |
$autoXlFormat | boolean | Determines whether the exported EXCEL cell data will be automatically guessed and formatted based on kartik\grid\DataColumn::$format property. | kartik\grid\GridViewTrait |
$beforeFooter | array|string | Configuration of additional footer table rows that will be rendered before the default grid footer row. | kartik\grid\GridViewTrait |
$beforeHeader | array|string | Configuration of additional header table rows that will be rendered before the default grid header row. | kartik\grid\GridViewTrait |
$bootstrap | boolean | Whether the grid view will have Bootstrap table styling. | kartik\grid\GridViewTrait |
$bordered | boolean | Whether the grid will have a bordered style. |
kartik\grid\GridViewTrait |
$condensed | boolean | Whether the grid will have a condensed style. |
kartik\grid\GridViewTrait |
$containerOptions | array|boolean | The HTML attributes for the grid container. | kartik\grid\GridViewTrait |
$defaultPagination | string | The default pagination that will be read by toggle data. | kartik\grid\GridViewTrait |
$editedRowConfig | array | The configuration for the row being currently edited | kartik\grid\GridViewTrait |
$enableEditedRow | boolean | Whether to enable focused edited row feature | kartik\grid\GridViewTrait |
$export | array|boolean | The grid export menu settings. | kartik\grid\GridViewTrait |
$exportConfig | array | The configuration for each export format. | kartik\grid\GridViewTrait |
$exportContainer | array | The HTML attributes for the export button group container. | kartik\grid\GridViewTrait |
$exportConversions | array | Conversion of defined patterns in the grid cells as a preprocessing before the gridview is formatted for export. | kartik\grid\GridViewTrait |
$floatFooter | boolean | Whether the grid will have a floating table footer. | kartik\grid\GridViewTrait |
$floatHeader | boolean | Whether the grid will have a floating table header. | kartik\grid\GridViewTrait |
$floatHeaderOptions | kartik\grid\GridViewTrait | ||
$floatOverflowContainer | kartik\grid\GridViewTrait | ||
$floatPageSummary | boolean | Whether the grid table will have a floating page summary at the bottom or top depending on
pageSummaryPosition . |
kartik\grid\GridViewTrait |
$footerContainer | array | The HTML options for the table tfoot container. |
kartik\grid\GridViewTrait |
$hashExportConfig | Whether to hash export config and prevent data tampering of the export config when transmitting this between
client and server during grid data export. Defaults to true . You may set this to false if your config
contains dynamic data (like current date time). However, note that when false it adds the possibility of
your client data being tampered during grid export when read by server. |
kartik\grid\GridViewTrait | |
$headerContainer | array | The HTML options for the table thead . |
kartik\grid\GridViewTrait |
$hideResizeMobile | boolean | Whether to hide resizable columns for smaller screen sizes (< 768px). | kartik\grid\GridViewTrait |
$hover | boolean | Whether the grid will highlight row on hover . |
kartik\grid\GridViewTrait |
$itemLabelAccusative | string | The default label shown for each record in the grid (accusative case). | kartik\grid\GridViewTrait |
$itemLabelFew | string | The default label shown for each record in the grid (plural). | kartik\grid\GridViewTrait |
$itemLabelMany | string | The default label shown for each record in the grid (plural). | kartik\grid\GridViewTrait |
$itemLabelPlural | string | The default label shown for each record in the grid (plural). | kartik\grid\GridViewTrait |
$itemLabelSingle | string | The default label shown for each record in the grid (singular). | kartik\grid\GridViewTrait |
$krajeeDialogSettings | array | Configuration settings for the Krajee dialog widget that will be used to render alerts and confirmation dialog prompts | kartik\grid\GridViewTrait |
$layout | string | The layout that determines how different sections of the list view should be organized. | kartik\grid\GridViewTrait |
$moduleId | string | The module identifier if this widget is part of a module. | kartik\grid\GridViewTrait |
$pageSummaryContainer | kartik\grid\GridViewTrait | ||
$pageSummaryPosition | string | Location of the page summary row (whether POS_TOP or POS_BOTTOM) | kartik\grid\GridViewTrait |
$pageSummaryRowOptions | kartik\grid\GridViewTrait | ||
$panel | array | The panel settings for displaying the grid view within a bootstrap styled panel. | kartik\grid\GridViewTrait |
$panelAfterTemplate | string | The template for rendering the `{after} part in the layout templates. | kartik\grid\GridViewTrait |
$panelBeforeTemplate | string | The template for rendering the `{before} part in the layout templates. | kartik\grid\GridViewTrait |
$panelFooterTemplate | string | The template for rendering the panel footer. | kartik\grid\GridViewTrait |
$panelHeadingTemplate | string | The template for rendering the panel heading. | kartik\grid\GridViewTrait |
$panelPrefix | string | The panel CSS prefix that will be applied to the panel container for rendering the grid within a bootstrap styled panel. | kartik\grid\GridViewTrait |
$panelTemplate | string | The template for rendering the grid within a bootstrap styled panel. | kartik\grid\GridViewTrait |
$perfectScrollbar | boolean | Whether pretty perfect scrollbars using perfect scrollbar plugin is to be used. | kartik\grid\GridViewTrait |
$perfectScrollbarOptions | array | The plugin options for the perfect scrollbar plugin. | kartik\grid\GridViewTrait |
$persistResize | boolean | Whether to store resized column state using local storage persistence (supported by most modern browsers). | kartik\grid\GridViewTrait |
$pjax | boolean | Whether the grid view will be rendered within a pjax container. | kartik\grid\GridViewTrait |
$pjaxSettings | array | The pjax settings for the widget. | kartik\grid\GridViewTrait |
$replaceTags | array | Tags to replace in the rendered layout. | kartik\grid\GridViewTrait |
$resizableColumns | boolean | Whether to allow resizing of columns | kartik\grid\GridViewTrait |
$resizableColumnsOptions | array | The resizableColumns plugin options | kartik\grid\GridViewTrait |
$resizeStorageKey | string | Resizable unique storage prefix to append to the grid id. | kartik\grid\GridViewTrait |
$responsive | boolean | Whether the grid will have a responsive style. |
kartik\grid\GridViewTrait |
$responsiveWrap | boolean | Whether the grid will automatically wrap to fit columns for smaller display sizes. | kartik\grid\GridViewTrait |
$showPageSummary | boolean | Whether to show the page summary row for the table. | kartik\grid\GridViewTrait |
$sorterIcons | array | The configuration for sorter icons. | kartik\grid\GridViewTrait |
$striped | boolean | Whether the grid will have a striped style. |
kartik\grid\GridViewTrait |
$toggleData | boolean | Whether to enable toggling of grid data. | kartik\grid\GridViewTrait |
$toggleDataContainer | array | The HTML attributes for the toggle data button group container. | kartik\grid\GridViewTrait |
$toggleDataOptions | array | The settings for the toggle data button for the toggle data type. | kartik\grid\GridViewTrait |
$toolbar | array|string | The toolbar content configuration. | kartik\grid\GridViewTrait |
$toolbarContainerOptions | array | The HTML attributes for the toolbar container. | kartik\grid\GridViewTrait |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$_filterCache | string|null | The filter cache | kartik\grid\GridViewTrait |
$_gridClientFunc | string | The generated client script for the grid | kartik\grid\GridViewTrait |
$_isShowAll | boolean | Whether the current mode is showing all data | kartik\grid\GridViewTrait |
$_module | kartik\grid\Module | The grid module. | kartik\grid\GridViewTrait |
$_toggleButtonId | string | HTML attribute identifier for the toggle button | kartik\grid\GridViewTrait |
$_toggleDataKey | string | Key to identify showing all data | kartik\grid\GridViewTrait |
$_toggleOptionsVar | string | The JS variable to store the toggle options | kartik\grid\GridViewTrait |
$_toggleScript | string | Generated plugin script for the toggle button | kartik\grid\GridViewTrait |
Public Methods
Method | Description | Defined By |
---|---|---|
getDefaultSorterIcons() | Gets default sorter icons | kartik\grid\GridViewTrait |
getPjaxContainerId() | Get pjax container identifier | kartik\grid\GridViewTrait |
initPjaxContainerId() | Initializes pjax container identifier | kartik\grid\GridViewTrait |
parseKey() | Parses the key and returns parsed key value as string based on the data type | kartik\grid\GridViewTrait |
renderExport() | Renders the export menu. | kartik\grid\GridViewTrait |
renderPageSummary() | Renders the table page summary. | kartik\grid\GridViewTrait |
renderTableRow() | Renders a table row with the given data model and key. | kartik\grid\GridViewTrait |
renderToggleData() | Renders the toggle data button. | kartik\grid\GridViewTrait |
Protected Methods
Method | Description | Defined By |
---|---|---|
beginPjax() | Begins the pjax widget rendering | kartik\grid\GridViewTrait |
endPjax() | Completes the pjax widget rendering | kartik\grid\GridViewTrait |
genToggleDataScript() | Generate toggle data client validation script. | kartik\grid\GridViewTrait |
generateRows() | Generate HTML markup for additional table rows for header and/or footer. | kartik\grid\GridViewTrait |
getPageSummaryRow() | Get the page summary row markup | kartik\grid\GridViewTrait |
initBootstrapStyle() | Initialize bootstrap specific styling. | kartik\grid\GridViewTrait |
initCss() | Sets a default css class within options if not set |
kartik\grid\GridViewTrait |
initEditedRow() | kartik\grid\GridViewTrait | |
initExport() | Initialize grid export. | kartik\grid\GridViewTrait |
initGridView() | Initializes the Krajee GridView widget | kartik\grid\GridViewTrait |
initLayout() | Initialize the grid layout. | kartik\grid\GridViewTrait |
initModule() | Initialize the module based on module identifier | kartik\grid\GridViewTrait |
initPanel() | Initializes and sets the grid panel layout based on the template and $panel settings. | kartik\grid\GridViewTrait |
initToggleData() | Initialize toggle data button options. | kartik\grid\GridViewTrait |
parseExportConfig() | Parses export configuration and returns the merged defaults. | kartik\grid\GridViewTrait |
prepareGridView() | Prepares the Krajee GridView widget for run | kartik\grid\GridViewTrait |
registerAssets() | Registers client assets for the kartik\grid\GridView widget. | kartik\grid\GridViewTrait |
renderTablePart() | Renders the table header or footer part | kartik\grid\GridViewTrait |
renderToolbar() | Generates the toolbar. | kartik\grid\GridViewTrait |
renderToolbarContainer() | Generates the toolbar container with the toolbar | kartik\grid\GridViewTrait |
replaceLayoutTokens() | Replace layout tokens | kartik\grid\GridViewTrait |
setPagerOptionClass() | Adds CSS class to the pager parameter | kartik\grid\GridViewTrait |
Property Details
The filter cache
The generated client script for the grid
Whether the current mode is showing all data
The grid module.
HTML attribute identifier for the toggle button
Key to identify showing all data
The JS variable to store the toggle options
Generated plugin script for the toggle button
Configuration of additional footer table rows that will be rendered after the default grid footer row. If set as a string, it will be displayed as is, without any HTML encoding. If set as an array, each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
columns
: array, the footer row columns configuration where you can set the following properties:content
: string, the grid cell content for the columntag
: string, the tag for rendering the grid cell. If not set, defaults toth
.options
: array, the HTML attributes for the grid cell
options
: array, the HTML attributes for the table row
Configuration of additional header table rows that will be rendered after default grid header row. If set as a string, it will be displayed as is, without any HTML encoding. If set as an array, each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
columns
: array, the header row columns configuration where you can set the following properties:content
: string, the grid cell content for the columntag
: string, the tag for rendering the grid cell. If not set, defaults toth
.options
: array, the HTML attributes for the grid cell
options
: array, the HTML attributes for the table row
Determines whether the exported EXCEL cell data will be automatically guessed and formatted based on kartik\grid\DataColumn::$format property. This property is applicable for EXCEL export content only. One can override this behavior and change the auto-derived format mask by setting kartik\grid\DataColumn::$xlFormat.
Configuration of additional footer table rows that will be rendered before the default grid footer row. If set as a string, it will be displayed as is, without any HTML encoding. If set as an array, each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
columns
: array, the footer row columns configuration where you can set the following properties:content
: string, the grid cell content for the columntag
: string, the tag for rendering the grid cell. If not set, defaults toth
.options
: array, the HTML attributes for the grid cell
options
: array, the HTML attributes for the table row
Configuration of additional header table rows that will be rendered before the default grid header row. If set as a string, it will be displayed as is, without any HTML encoding. If set as an array, each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
columns
: array, the header row columns configuration where you can set the following properties:content
: string, the grid cell content for the columntag
: string, the tag for rendering the grid cell. If not set, defaults toth
.options
: array, the HTML attributes for the grid cell
options
: array, the HTML attributes for the table row
Whether the grid view will have Bootstrap table styling.
Whether the grid will have a bordered
style. Applicable only if bootstrap
is true
.
Whether the grid will have a condensed
style. Applicable only if bootstrap
is true
.
The HTML attributes for the grid container. The grid items will be wrapped in a div
container with the configured HTML attributes. The ID for the container will be auto generated.
The default pagination that will be read by toggle data. Should be one of 'page' or 'all'. If not set to 'all', it will always defaults to 'page'.
The configuration for the row being currently edited
'rowIdGetParam' => 'row', 'gridIdGetParam' => 'grid', 'gridFiltersSessionParam' => 'kvGridFiltersCache', 'highlightClass' => 'kv-row-edit-highlight'
]
Whether to enable focused edited row feature
The grid export menu settings. Displays a Bootstrap dropdown menu that allows you to export the
grid as either html, csv, or excel. If set to false
, will not be displayed. The following options can be
set:
icon
: string,the glyphicon suffix to be displayed before the export menu label. If not set or is an empty string, this will not be displayed. Defaults toexport
iffontAwesome
isfalse
andshare-square-o
if fontAwesome istrue
.label
: string,the export menu label (this is not HTML encoded). Defaults to ''.showConfirmAlert
: bool, whether to show a confirmation alert dialog before download. This confirmation dialog will notify user about the type of exported file for download and to disable popup blockers. Defaults totrue
.target
: string, the target for submitting the export form, which will trigger the download of the exported file. Must be one of theTARGET_
constants. Defaults toGridView::TARGET_POPUP
.messages
: array, the configuration of various messages that will be displayed at runtime:allowPopups
: string, the message to be shown to disable browser popups for download. Defaults toDisable any popup blockers in your browser to ensure proper download.
.confirmDownload
: string, the message to be shown for confirming to proceed with the download. Defaults toOk to proceed?
.downloadProgress
: string, the message to be shown in a popup dialog when download request is triggered. Defaults toGenerating file. Please wait...
.downloadComplete
: string, the message to be shown in a popup dialog when download request is completed. Defaults toAll done! Click anywhere here to close this window, once you have downloaded the file.
.
header
: string, the header for the page data export dropdown. If set to empty string will not be displayed. Defaults to:<li role="presentation" class="dropdown-header">Export Page Data</li>
.fontAwesome
: bool, whether to use font awesome file type icons. Defaults tofalse
. If you set it totrue
, then font awesome icons css class will be applied instead of glyphicons.itemsBefore
: array, any additional items that will be merged/prepended before with the export dropdown list. This should be similar to theitems
property as supported by\yii\bootstrap\ButtonDropdown
widget. Note the page export items will be automatically generated based on settings in theexportConfig
property.itemsAfter
: array, any additional items that will be merged/appended after with the export dropdown list. This should be similar to theitems
property as supported by\yii\bootstrap\ButtonDropdown
widget. Note the page export items will be automatically generated based on settings in theexportConfig
property.options
: array, HTML attributes for the export menu button. Defaults to['class' => 'btn btn-default']
for bsVersion = '3.x' or .['class' => 'btn btn-secondary']
for bsVersion = '4.x' / '5.x'
encoding
: string, the export output file encoding. If not set, defaults toutf-8
.bom
:boolean
, whether a BOM is to be embedded for text or CSV files with utf-8 encoding. Defaults totrue
.menuOptions
: array, HTML attributes for the export dropdown menu. Defaults to['class' => 'dropdown-menu dropdown-menu-right']
. This property is to be setup exactly as theoptions
property required by the yii\bootstrap\Dropdown widget.skipExportElements
: array, the list of jQuery element selectors that will be skipped and removed from export. Defaults to['.sr-only', '.hide']
.
The configuration for each export format. The array keys must be the one of the format
constants
(CSV, HTML, TEXT, EXCEL, PDF, JSON) and the array value is a configuration array consisiting of these settings:
label
: string,the label for the export format menu item displayedicon
: string,the glyphicon or font-awesome name suffix to be displayed before the export menu item label. If set to an empty string, this will not be displayed. ReferdefaultConfig
ininitExport
method for default settings.showHeader
:boolean
, whether to show table header row in the output. Defaults totrue
.showPageSummary
:boolean
, whether to show table page summary row in the output. Defaults totrue
.showFooter
:boolean
, whether to show table footer row in the output. Defaults totrue
.showCaption
:boolean
, whether to show table caption in the output (only for HTML). Defaults totrue
.filename
: the base file name for the generated file. Defaults to 'grid-export'. This will be used to generate a default file name for downloading (extension will be one of csv, html, or xls - `based on the format setting).alertMsg
: string, the message prompt to show before saving. If this is empty or not set it will not be displayed.options
: array, HTML attributes for the export format menu item.mime
: string, the mime type (for the file format) to be set before downloading.config
: array, the special configuration settings specific to each file format/type. The following configuration options are read specific to each file type:HTML
: The following properties can be set as array key-value pairs:cssFile
: string, the css file that will be used in the exported HTML file. Defaults to:https://maxcdn.bootstrapcdn.com/bootstrap/3.5.0/css/bootstrap.min.css
.
CSV
andTEXT
: The following properties can be set as array key-value pairs:colDelimiter
: string, the column delimiter string for TEXT and CSV downloads.rowDelimiter
: string, the row delimiter string for TEXT and CSV downloads.
EXCEL
: The following properties can be set as array key-value pairs:worksheet
: string, the name of the worksheet, when saved as EXCEL file.
PDF
: Supports all configuration properties as required in kartik\mpdf\Pdf extension. In addition, the following additional special options are recognized:contentBefore
: string, any HTML formatted content that will be embedded in the PDF output before the grid.contentAfter
: string, any HTML formatted content that will be embedded in the PDF output after the grid.
JSON
: The following properties can be set as array key-value pairs:colHeads
: array, the column heading names to be output in the json file. If not set, it will be autogenerated as "col-{i}", where {i} is the column index. IfslugColHeads
is set totrue
, the extension will attempt to autogenerate column heads based on table column heading, whereever possible.slugColHeads
:boolean
, whether to auto-generate column identifiers as slugs based on the table column heading name. If the table column heading contains characters which cannot be slugified, then the extension will autogenerate the column name as "col-{i}".jsonReplacer
: array|JsExpression, the JSON replacer property -
can be an array or a JS function created using JsExpression. Refer the JSON documentation for details on setting this property.indentSpace
: int, pretty print json output and indent by number of spaces specified. Defaults to4
.
The HTML attributes for the export button group container. By default this will always have the
class = btn-group
automatically added, if no class is set.
Conversion of defined patterns in the grid cells as a preprocessing before the gridview is formatted for export. Each array row must consist of the following two keys:
from
: string, is the pattern to search for in each grid column's cellsto
: string, is the string to replace the pattern in the grid column cells This defaults to:[ ['from'=>GridView::ICON_ACTIVE, 'to'=>Yii::t('kvgrid', 'Active')], ['from'=>GridView::ICON_INACTIVE, 'to'=>Yii::t('kvgrid', 'Inactive')] ]
Whether the grid will have a floating table footer.
Whether the grid will have a floating table header. Note that the table header will stick to the
top of the page by default if this is set to true
. To add an offset - you can configure the CSS style
within headerContainer
- for example:
'headerContainer' => ['class' => 'kv-table-header, 'style' => 'top: 50px'] // to set an offset
Whether the grid table will have a floating page summary at the bottom or top depending on
pageSummaryPosition
. Defaults to false
. Note that this property also automatically overrides and disables
the floatHeader
or floatFooter
properties. This is because only one sticky container can exist at the top
or bottom. Note:
- when
pageSummaryPosition
is set toGridView::POS_BOTTOM
, the page summary sticks to the bottom of the page, and overrides thefloatFooter
setting tofalse
. - when
pageSummaryPosition
is set toGridView::POS_TOP
, the page summary sticks to the top of the page, and overrides thefloatHeader
setting tofalse
. Note that, like header or footer, you can control the positioning or offset of the page summary container viapageSummaryContainer
.
'pageSummaryContainer' => ['style' => 'top: 50px'] // to set an offset
The HTML options for the table tfoot
container. The CSS class 'kv-table-footer' is added
by default, and creates the Krajee default footer styling for a better float footer behavior. In case you are
overriding this property at runtime, either use your own CSS class/ style or add the default CSS
'kv-table-footer' for maintaining a consistent sticky styling. Similar, to headerContainer
, you can control
other styling, like offsets. For example:
'footerContainer' => ['class' => 'kv-table-footer, 'style' => 'bottom: 50px'] // to set an offset from bottom
The HTML options for the table thead
. The CSS class 'kv-table-header' is added by default and
creates the Krajee default header styling for a better float header behavior. In case you are overriding this
property at runtime, either use your own CSS class/ style or add the default CSS 'kv-table-header'. Note that
with floatHeader
enabled to true
, you may need to add an offset for the floated header from top when
scrolling (e.g. in cases where you have a fixed bootstrap navbar on top). For example:
'headerContainer' => ['class' => 'kv-table-header, 'style' => 'top: 50px'] // to set an offset
Whether to hide resizable columns for smaller screen sizes (< 768px). Defaults to true
.
Whether the grid will highlight row on hover
. Applicable only if bootstrap
is true
.
The default label shown for each record in the grid (accusative case). This is applicable for few languages like German.
The default label shown for each record in the grid (plural). Similar to $itemLabelPlural but
this is applicable for languages like russian, where the plural label can be different for fewer item count.
This label will replace the plural word items-few
within the grid summary text.
The default label shown for each record in the grid (plural). Similar to $itemLabelPlural but
this is applicable for languages like russian, where the plural label can be different for many item count.
This label will replace the plural word items-many
within the grid summary text.
The default label shown for each record in the grid (plural). This label will replace the plural word
items
within the grid summary text.
The default label shown for each record in the grid (singular). This label will replace the singular
word item
within the grid summary text as well as ActionColumn default delete confirmation message.
Configuration settings for the Krajee dialog widget that will be used to render alerts and confirmation dialog prompts
See also http://demos.krajee.com/dialog.
The layout that determines how different sections of the list view should be organized.
The layout template will be automatically set based on the $panel setting. If $panel is a valid
array, then the $layout will default to the $panelTemplate property. If the $panel property
is set to false
, then the $layout will default to {summary}\n{items}\n{pager}
.
The following tokens will be replaced with the corresponding section contents:
{summary}
: the summary section. See renderSummary().{errors}
: the filter model error summary. See renderErrors().{items}
: the list items. See renderItems().{sorter}
: the sorter. See renderSorter().{pager}
: the pager. See renderPager().{export}
: the grid export button menu. See renderExport().{toolbar}
: the grid panel toolbar. See renderToolbar().{toolbarContainer}
: the toolbar container. See renderToolbarContainer().
In addition to the above tokens, refer the $panelTemplate property for other tokens supported as part of the bootstrap styled panel.
The module identifier if this widget is part of a module. If not set, the module identifier will
be auto derived based on the \yii\base\Module::getInstance method. This can be useful, if you are setting
multiple module identifiers for the same module in your Yii configuration file. To specify children or grand
children modules you can specify the module identifiers relative to the parent module (e.g. admin/content
).
Location of the page summary row (whether POS_TOP or POS_BOTTOM)
The panel settings for displaying the grid view within a bootstrap styled panel. This property is
therefore applicable only if $bootstrap property is true
. The following array keys can be configured:
type
: string, the panel contextual type. Set it to one of the TYPE constants. If not set, will default to TYPE_DEFAULT.options
: array, the HTML attributes for the panel container. If theclass
is not set, it will be auto derived using the paneltype
and $panelPrefixheading
:string
|boolean
, the panel heading. If set tofalse
, will not be displayed.headingOptions
: array, HTML attributes for the panel heading container. Defaults to:['class'=>'panel-heading']
when bsVersion =3.x
, and['class'=>'card-heading <COLOR>']
when bsVersion =4.x
- the color will be auto calculated based on thetype
setting
titleOptions
: array, HTML attributes for the panel title container. The following tags are specially parsed:tag
: string, the HTML tag to render the title. Defaults toh3
when bsVersion =3.x
andspan
when bsVersion =4.x
ThetitleOptions
defaults to:['class'=>'panel-title']
when bsVersion =3.x
, and[]
when bsVersion =4.x
summaryOptions
: array, HTML attributes for the panel summary section container. Defaults to:['class'=>'pull-right']
when bsVersion =3.x
, and['class'=>'float-right']
when bsVersion =4.x
, and
footer
:string
|boolean
, the panel footer. If set tofalse
will not be displayed.footerOptions
: array, HTML attributes for the panel footer container. Defaults to:['class'=>'panel-footer']
when bsVersion =3.x
, and['class'=>'card-footer']
when bsVersion =4.x
- 'before':
string
|boolean
, content to be placed before/above the grid (after the header). To not display this section, set this tofalse
. beforeOptions
: array, HTML attributes for thebefore
text. If theclass
is not set, it will default tokv-panel-before
.- 'after':
string
|boolean
, any content to be placed after/below the grid (before the footer). To not display this section, set this tofalse
. afterOptions
: array, HTML attributes for theafter
text. If theclass
is not set, it will default tokv-panel-after
.
The template for rendering the `{after} part in the layout templates. The following special variables are recognized and will be replaced:
{after}
: string, which will render theafter
text passed within the $panel settings{summary}
: string, which will render the grid results summary.{items}
: string, which will render the grid items.{sort}
: string, which will render the grid sort links.{pager}
: string, which will render the grid pagination links.{toolbar}
: string, which will render the $toolbar property passed{toolbarContainer}
: string, which will render the toolbar container. See renderToolbarContainer().{export}
: string, which will render the $export menu button content
The template for rendering the `{before} part in the layout templates. The following special tokens are recognized and will be replaced:
{before}
: string, which will render the before text passed in the panel settings{summary}
: string, which will render the grid results summary.{items}
: string, which will render the grid items.{sort}
: string, which will render the grid sort links.{pager}
: string, which will render the grid pagination links.{toolbar}
: string, which will render the $toolbar property passed{toolbarContainer}
: string, which will render the toolbar container. See renderToolbarContainer().{export}
: string, which will render the $export menu button content
The template for rendering the panel footer. The following special tokens are recognized and will be replaced:
{title}
: string, which will render the panel heading title content.{footer}
: string, which will render the panel footer content.{summary}
: string, which will render the grid results summary.{items}
: string, which will render the grid items.{sort}
: string, which will render the grid sort links.{pager}
: string, which will render the grid pagination links.{toolbar}
: string, which will render the $toolbar property passed{export}
: string, which will render the $export menu button content
The template for rendering the panel heading. The following special tokens are recognized and will be replaced:
{title}
: string, which will render the panel heading title content.{summary}
: string, which will render the grid results summary.{items}
: string, which will render the grid items.{pager}
: string, which will render the grid pagination links.{sort}
: string, which will render the grid sort links.{toolbar}
: string, which will render the $toolbar property passed{toolbarContainer}
: string, which will render the toolbar container. See renderToolbarContainer().{export}
: string, which will render the $export menu button content.
The panel CSS prefix that will be applied to the panel container for rendering the grid
within a bootstrap styled panel. This can be set to a different value to generate different styles for
other bootstrap themes. For example, this can be set to box box-
for rendering boxes in AdminLTE theme.
The template for rendering the grid within a bootstrap styled panel. The following special tokens are recognized and will be replaced:
{prefix}
: string, the CSS prefix name as set in $panelPrefix. Defaults topanel panel-
.{type}
: string, the panel type that will append the bootstrap contextual CSS.{panelHeading}
: string, which will render the panel heading block.{panelBefore}
: string, which will render the panel before block.{panelAfter}
: string, which will render the panel after block.{panelFooter}
: string, which will render the panel footer block.{items}
: string, which will render the grid items.{summary}
: string, which will render the grid results summary.{pager}
: string, which will render the grid pagination links.{toolbar}
: string, which will render the $toolbar property passed{toolbarContainer}
: string, which will render the toolbar container. See renderToolbarContainer().{export}
: string, which will render the $export menu button content.
Whether pretty perfect scrollbars using perfect scrollbar plugin is to be used. Defaults to
false
.
The plugin options for the perfect scrollbar plugin.
Whether to store resized column state using local storage persistence (supported by most modern browsers).
Whether the grid view will be rendered within a pjax container. Defaults to false
. If set to
true
, the entire GridView widget will be parsed via Pjax and auto-rendered inside a yii\widgets\Pjax
widget container. If set to false
pjax will be disabled and none of the pjax settings will be applied.
The pjax settings for the widget. This will be considered only when $pjax is set to true. The following settings are recognized:
neverTimeout
:boolean
, whether the pjax request should never timeout. Defaults totrue
. The pjax:timeout event will be configured to disable timing out of pjax requests for the pjax container.options
: array, the options for the yii\widgets\Pjax widget.loadingCssClass
: boolean/string, the CSS class to be applied to the grid when loading via pjax. If set tofalse
- no css class will be applied. If it is empty, null, or set totrue
, will default tokv-grid-loading
.beforeGrid
: string, any content to be embedded within pjax container before the Grid widget.afterGrid
: string, any content to be embedded within pjax container after the Grid widget.
Tags to replace in the rendered layout. Enter this as $key => $callback
pairs, where:
$key
: string, defines the flag.$callback
: string|array, the callback function name that will return the value to be replaced. This can be a global function name or a callback setting in an array format as understood by PHP'scall_user_func_array
method.
For example:
function renderTag1() { // global function
$string = ''; // do your stuff to render;
return $string;
};
echo GridView::widget([
'replaceTags' => [
'{tag1}' => 'renderTag1'
]
// other gridview settings
]);
Alternatively you can return a function name from your class or object as an array format. For example:
class YourClass {
public function renderToken2() { // object function
$string = ''; // do your stuff to render;
return $string;
}
public static function renderToken3() { // static function
$string = ''; // do your stuff to render;
return $string;
}
public function render() {
return GridView::widget([
'replaceTags' => [
'{token2}' => [$this, 'renderToken2'],
'{token3}' => [YourClass::class, 'renderToken3']
]
// other gridview settings
]);
}
}
Whether to allow resizing of columns
The resizableColumns plugin options
Resizable unique storage prefix to append to the grid id. If empty or not set it will default to
Yii::$app->user->id
.
Whether the grid will have a responsive
style. Applicable only if bootstrap
is true
.
Note that if you set this to true
and floatHeader
or floatFooter
or floatPageSummary
is also
enabled to true
- then for effective behavior set a fixed height for the container in containerOptions
or add the built in class kv-grid-wrapper
to the containerOptions
- for example:
`
'containerOptions' => ['class' => 'kv-grid-wrapper']
Whether the grid will automatically wrap to fit columns for smaller display sizes.
Whether to show the page summary row for the table. This will be displayed above the footer.
The configuration for sorter icons. The array key must have an SORT_ASC
and SORT_DESC
entry.
The sorterIcons
property defaults to following if not overridden:
For Bootstrap v4.x and v5.x: [ SORT_ASC => '', SORT_DESC => '' ]
For Bootstrap v3.x: [ SORT_ASC => '', SORT_DESC => '', ]
Whether the grid will have a striped
style. Applicable only if bootstrap
is true
.
Whether to enable toggling of grid data. Defaults to true
.
The HTML attributes for the toggle data button group container. By default this will always have the
class = btn-group
automatically added, if no class is set.
The settings for the toggle data button for the toggle data type. This will be setup as an associative array of $key => $value pairs, where $key can be:
maxCount
:int
|boolean
, the maximum number of records uptil which the toggle button will be rendered. If the dataProvider records exceed this setting, the toggleButton will not be displayed. Defaults to10000
if not set. If you set this totrue
, the toggle button will always be displayed. If you set this tofalse the toggle button will not be displayed (similar to
toggleData` setting).minCount
:int
|boolean
, the minimum number of records beyond which a confirmation message will be displayed when toggling all records. If the dataProvider record count exceeds this setting, a confirmation message will be alerted to the user. Defaults to500
if not set. If you set this totrue
, the confirmation message will always be displayed. If set tofalse
no confirmation message will be displayed.confirmMsg
: string, the confirmation message for the toggle data whenminCount
threshold is exceeded. Defaults to'There are {totalCount} records. Are you sure you want to display them all?'
.all
: array, configuration for showing all grid data and the value is the HTML attributes for the button. (referpage
for understanding the default options).page
: array, configuration for showing first page data and $options is the HTML attributes for the button. The following special options are recognized:icon
: string, the glyphicon suffix name. If not set or empty will not be displayed.label
: string, the label for the button.This defaults to the following setting:
[ 'maxCount' => 10000, 'minCount' => 1000 'confirmMsg' => Yii::t( 'kvgrid', 'There are {totalCount} records. Are you sure you want to display them all?', ['totalCount' => number_format($this->dataProvider->getTotalCount())] ), 'all' => [ 'icon' => 'resize-full', 'label' => 'All', 'class' => 'btn btn-default', // 'btn btn-secondary' for BS4.x / BS5.x 'title' => 'Show all data' ], 'page' => [ 'icon' => 'resize-small', 'label' => 'Page', 'class' => 'btn btn-default', // 'btn btn-secondary' for BS4.x / BS5.x 'title' => 'Show first page data' ], ]
The toolbar content configuration. Can be setup as a string or an array. When set as a string, it will be rendered as is. When set as an array, each line item will be considered as per the following rules:
- if the line item is setup as a string, it will be rendered as is
- if the line item is an array, the following keys can be setup to control the rendering of the toolbar:
content
: string, the content to be rendered as a bootstrap button group. The following special tags in the content are recognized and will be replaced:{export}
, string which will render the $export menu button content.{toggleData}
, string which will render the button to toggle between page data and all data.options
: array, the HTML attributes for the button group div container. By default the CSS classbtn-group
will be attached to this container if no class is set.
The HTML attributes for the toolbar container. The following special attributes are recognized:
tag
: string, the HTML tag to render the toolbar container. Defaults todiv
.
'class' => 'btn-toolbar kv-grid-toolbar toolbar-container'
]
Method Details
Begins the pjax widget rendering
protected void beginPjax ( ) |
Completes the pjax widget rendering
protected void endPjax ( ) |
Generate toggle data client validation script.
protected void genToggleDataScript ( ) |
Generate HTML markup for additional table rows for header and/or footer.
protected string generateRows ( $data ) | ||
$data | array|string | The table rows configuration |
throws | Exception |
---|
Gets default sorter icons
public static array getDefaultSorterIcons ( $notBs3 ) | ||
$notBs3 | boolean |
Get the page summary row markup
protected string getPageSummaryRow ( ) | ||
throws | Exception |
---|
Get pjax container identifier
public string getPjaxContainerId ( ) |
Initialize bootstrap specific styling.
protected void initBootstrapStyle ( ) | ||
throws | Exception |
---|
Sets a default css class within options
if not set
protected static void initCss ( &$options, $css ) | ||
$options | array | The HTML options |
$css | string|array | The CSS class to test and append |
protected array|false initEditedRow ( ) |
Initialize grid export.
protected void initExport ( ) | ||
throws | Exception |
---|
Initializes the Krajee GridView widget
protected void initGridView ( ) | ||
throws | yii\base\InvalidConfigException |
---|
Initialize the grid layout.
protected void initLayout ( ) | ||
throws | yii\base\InvalidConfigException |
---|
Initialize the module based on module identifier
protected void initModule ( ) | ||
throws | yii\base\InvalidConfigException |
---|
Initializes and sets the grid panel layout based on the template and $panel settings.
protected void initPanel ( ) | ||
throws | Exception |
---|
Initializes pjax container identifier
public void initPjaxContainerId ( ) |
Initialize toggle data button options.
protected void initToggleData ( ) | ||
throws | Exception |
---|
Parses export configuration and returns the merged defaults.
protected static array parseExportConfig ( $exportConfig, $defaultExportConfig ) | ||
$exportConfig | array | The export configuration |
$defaultExportConfig | array | The default export configuration |
Parses the key and returns parsed key value as string based on the data type
public static string parseKey ( $key ) | ||
$key | mixed |
Prepares the Krajee GridView widget for run
protected void prepareGridView ( ) | ||
throws | yii\base\InvalidConfigException |
---|
Registers client assets for the kartik\grid\GridView widget.
protected void registerAssets ( ) | ||
throws | Exception |
---|
Renders the export menu.
public string renderExport ( ) | ||
throws | yii\base\InvalidConfigException | |
---|---|---|
throws | Exception |
Renders the table page summary.
public string renderPageSummary ( ) | ||
return | string | The rendering result. |
---|---|---|
throws | Exception |
Renders the table header or footer part
protected string renderTablePart ( $part, $content ) | ||
$part | string | Whether thead or tfoot |
$content | string | |
throws | Exception |
---|
Renders a table row with the given data model and key.
public string renderTableRow ( $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 dataProvider. |
return | string | The rendering result |
---|
Renders the toggle data button.
public string renderToggleData ( ) | ||
throws | Exception |
---|
Generates the toolbar.
protected string renderToolbar ( ) | ||
throws | Exception |
---|
Generates the toolbar container with the toolbar
protected void renderToolbarContainer ( ) | ||
throws | Exception |
---|
Replace layout tokens
protected void replaceLayoutTokens ( $pairs ) | ||
$pairs | array | The token to find and its replaced value as key value pairs |
Adds CSS class to the pager parameter
protected void setPagerOptionClass ( $param, $css ) | ||
$param | string | The pager param |
$css | string | The CSS class |
throws | Exception |
---|