Trait kartik\grid\GridViewTrait

Implemented bykartik\export\ExportMenu, kartik\grid\GridView
Available since version1.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

Hide inherited properties

PropertyTypeDescriptionDefined 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

Hide inherited properties

PropertyTypeDescriptionDefined 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

Hide inherited methods

MethodDescriptionDefined 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

Hide inherited methods

MethodDescriptionDefined 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

$_filterCache protected property

The filter cache

protected string|null $_filterCache null
$_gridClientFunc protected property

The generated client script for the grid

protected string $_gridClientFunc ''
$_isShowAll protected property

Whether the current mode is showing all data

protected boolean $_isShowAll false
$_module protected property

The grid module.

protected kartik\grid\Module $_module null
$_toggleButtonId protected property

HTML attribute identifier for the toggle button

protected string $_toggleButtonId null
$_toggleDataKey protected property

Key to identify showing all data

protected string $_toggleDataKey null
$_toggleOptionsVar protected property

The JS variable to store the toggle options

protected string $_toggleOptionsVar null
$_toggleScript protected property

Generated plugin script for the toggle button

protected string $_toggleScript null
$afterFooter public property

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 column
    • tag: string, the tag for rendering the grid cell. If not set, defaults to th.
    • options: array, the HTML attributes for the grid cell
  • options: array, the HTML attributes for the table row
$afterHeader public property

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 column
    • tag: string, the tag for rendering the grid cell. If not set, defaults to th.
    • options: array, the HTML attributes for the grid cell
  • options: array, the HTML attributes for the table row
$autoXlFormat public property

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.

public boolean $autoXlFormat false
$beforeFooter public property

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 column
    • tag: string, the tag for rendering the grid cell. If not set, defaults to th.
    • options: array, the HTML attributes for the grid cell
  • options: array, the HTML attributes for the table row
$beforeHeader public property

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 column
    • tag: string, the tag for rendering the grid cell. If not set, defaults to th.
    • options: array, the HTML attributes for the grid cell
  • options: array, the HTML attributes for the table row
$bootstrap public property

Whether the grid view will have Bootstrap table styling.

public boolean $bootstrap true
$bordered public property

Whether the grid will have a bordered style. Applicable only if bootstrap is true.

public boolean $bordered true
$condensed public property

Whether the grid will have a condensed style. Applicable only if bootstrap is true.

public boolean $condensed false
$containerOptions public property

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.

$defaultPagination public property

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'.

public string $defaultPagination 'page'
$editedRowConfig public property

The configuration for the row being currently edited

public array $editedRowConfig = [
    'rowIdGetParam' => 'row''gridIdGetParam' => 'grid''gridFiltersSessionParam' => 'kvGridFiltersCache''highlightClass' => 'kv-row-edit-highlight'
]
$enableEditedRow public property

Whether to enable focused edited row feature

public boolean $enableEditedRow false
$export public property

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 to export if fontAwesome is false and share-square-o if fontAwesome is true.
  • 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 to true.
  • target: string, the target for submitting the export form, which will trigger the download of the exported file. Must be one of the TARGET_ constants. Defaults to GridView::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 to Disable 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 to Ok to proceed?.
    • downloadProgress: string, the message to be shown in a popup dialog when download request is triggered. Defaults to Generating file. Please wait....
    • downloadComplete: string, the message to be shown in a popup dialog when download request is completed. Defaults to All 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 to false. If you set it to true, 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 the items property as supported by \yii\bootstrap\ButtonDropdown widget. Note the page export items will be automatically generated based on settings in the exportConfig property.
  • itemsAfter: array, any additional items that will be merged/appended after with the export dropdown list. This should be similar to the items property as supported by \yii\bootstrap\ButtonDropdown widget. Note the page export items will be automatically generated based on settings in the exportConfig 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 to utf-8.
  • bom: boolean, whether a BOM is to be embedded for text or CSV files with utf-8 encoding. Defaults to true.
  • 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 the options 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'].
public array|boolean $export = []
$exportConfig public property

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 displayed
  • icon: 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. Refer defaultConfig in initExport method for default settings.
  • showHeader: boolean, whether to show table header row in the output. Defaults to true.
  • showPageSummary: boolean, whether to show table page summary row in the output. Defaults to true.
  • showFooter: boolean, whether to show table footer row in the output. Defaults to true.
  • showCaption: boolean, whether to show table caption in the output (only for HTML). Defaults to true.
  • 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 and TEXT: 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. If slugColHeads is set to true, 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 to 4.
public array $exportConfig = []
$exportContainer public property

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.

public array $exportContainer = []
$exportConversions public property

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 cells
  • to: 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')]
    ]
    
$floatFooter public property

Whether the grid will have a floating table footer.

public boolean $floatFooter false
$floatHeader public property

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
public boolean $floatHeader false
$floatHeaderOptions public property
Deprecated since release v3.5.0
public $floatHeaderOptions = []
$floatOverflowContainer public property
Deprecated since release v3.5.0
public $floatOverflowContainer false
$floatPageSummary public property

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 to GridView::POS_BOTTOM, the page summary sticks to the bottom of the page, and overrides the floatFooter setting to false.
  • when pageSummaryPosition is set to GridView::POS_TOP, the page summary sticks to the top of the page, and overrides the floatHeader setting to false. Note that, like header or footer, you can control the positioning or offset of the page summary container via pageSummaryContainer.
   'pageSummaryContainer' => ['style' => 'top: 50px'] // to set an offset
public boolean $floatPageSummary false
$footerContainer public property

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
public array $footerContainer = [
    'class' => 'kv-table-footer'
]
$hashExportConfig public property
public $hashExportConfig true
$headerContainer public property

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
public array $headerContainer = [
    'class' => 'kv-table-header'
]
$hideResizeMobile public property

Whether to hide resizable columns for smaller screen sizes (< 768px). Defaults to true.

public boolean $hideResizeMobile true
$hover public property

Whether the grid will highlight row on hover. Applicable only if bootstrap is true.

public boolean $hover false
$itemLabelAccusative public property

The default label shown for each record in the grid (accusative case). This is applicable for few languages like German.

$itemLabelFew public property

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.

public string $itemLabelFew null
$itemLabelMany public property

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.

public string $itemLabelMany null
$itemLabelPlural public property

The default label shown for each record in the grid (plural). This label will replace the plural word items within the grid summary text.

public string $itemLabelPlural null
$itemLabelSingle public property

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.

public string $itemLabelSingle null
$krajeeDialogSettings public property

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.

$layout public property

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.

public string $layout "{summary}\n{items}\n{pager}"
$moduleId public property

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).

public string $moduleId null
$pageSummaryContainer public property
public $pageSummaryContainer = [
    'class' => 'kv-page-summary-container'
]
$pageSummaryPosition public property

Location of the page summary row (whether POS_TOP or POS_BOTTOM)

public string $pageSummaryPosition self::POS_BOTTOM
$pageSummaryRowOptions public property
$panel public property

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 the class is not set, it will be auto derived using the panel type and $panelPrefix
  • heading: string|boolean, the panel heading. If set to false, 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 the type 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 to h3 when bsVersion = 3.x and span when bsVersion = 4.x The titleOptions 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 to false 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 to false.
  • beforeOptions: array, HTML attributes for the before text. If the class is not set, it will default to kv-panel-before.
  • 'after': string|boolean, any content to be placed after/below the grid (before the footer). To not display this section, set this to false.
  • afterOptions: array, HTML attributes for the after text. If the class is not set, it will default to kv-panel-after.
public array $panel = []
$panelAfterTemplate public property

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 the after 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
public string $panelAfterTemplate '{after}'
$panelBeforeTemplate public property

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
$panelFooterTemplate public property

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
$panelHeadingTemplate public property

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.
$panelPrefix public property

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.

public string $panelPrefix null
$panelTemplate public property

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 to panel 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.
$perfectScrollbar public property

Whether pretty perfect scrollbars using perfect scrollbar plugin is to be used. Defaults to false.

See also https://github.com/utatti/perfect-scrollbar.

public boolean $perfectScrollbar false
$perfectScrollbarOptions public property

The plugin options for the perfect scrollbar plugin.

See also https://github.com/noraesae/perfect-scrollbar.

$persistResize public property

Whether to store resized column state using local storage persistence (supported by most modern browsers).

public boolean $persistResize false
$pjax public property

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.

public boolean $pjax false
$pjaxSettings public property

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 to true. 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 to false - no css class will be applied. If it is empty, null, or set to true, will default to kv-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.
public array $pjaxSettings = []
$replaceTags public property

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's call_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
        ]);
    }
}
public array $replaceTags = []
$resizableColumns public property

Whether to allow resizing of columns

public boolean $resizableColumns true
$resizableColumnsOptions public property

The resizableColumns plugin options

public array $resizableColumnsOptions = [
    'resizeFromBody' => false
]
$resizeStorageKey public property

Resizable unique storage prefix to append to the grid id. If empty or not set it will default to Yii::$app->user->id.

public string $resizeStorageKey null
$responsive public property

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']
public boolean $responsive true
$responsiveWrap public property

Whether the grid will automatically wrap to fit columns for smaller display sizes.

public boolean $responsiveWrap true
$showPageSummary public property

Whether to show the page summary row for the table. This will be displayed above the footer.

public boolean $showPageSummary false
$sorterIcons public property

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 => '', ]

public array $sorterIcons = []
$striped public property

Whether the grid will have a striped style. Applicable only if bootstrap is true.

public boolean $striped true
$toggleData public property

Whether to enable toggling of grid data. Defaults to true.

public boolean $toggleData true
$toggleDataContainer public property

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.

$toggleDataOptions public property

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 to 10000 if not set. If you set this to true, the toggle button will always be displayed. If you set this to false 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 to 500 if not set. If you set this to true, the confirmation message will always be displayed. If set to false no confirmation message will be displayed.
  • confirmMsg: string, the confirmation message for the toggle data when minCount 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. (refer page 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'
          ],
      ]
      
$toolbar public property

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 class btn-group will be attached to this container if no class is set.
public array|string $toolbar = [
    '{toggleData}''{export}'
]
$toolbarContainerOptions public property

The HTML attributes for the toolbar container. The following special attributes are recognized:

  • tag: string, the HTML tag to render the toolbar container. Defaults to div.
public array $toolbarContainerOptions = [
    'class' => 'btn-toolbar kv-grid-toolbar toolbar-container'
]

Method Details

beginPjax() protected method

Begins the pjax widget rendering

protected void beginPjax ( )
endPjax() protected method

Completes the pjax widget rendering

protected void endPjax ( )
genToggleDataScript() protected method

Generate toggle data client validation script.

protected void genToggleDataScript ( )
generateRows() protected method

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
getDefaultSorterIcons() public static method

Gets default sorter icons

public static array getDefaultSorterIcons ( $notBs3 )
$notBs3 boolean
getPageSummaryRow() protected method

Get the page summary row markup

protected string getPageSummaryRow ( )
throws Exception
getPjaxContainerId() public method

Get pjax container identifier

public string getPjaxContainerId ( )
initBootstrapStyle() protected method

Initialize bootstrap specific styling.

protected void initBootstrapStyle ( )
throws Exception
initCss() protected static method

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

initEditedRow() protected method

protected array|false initEditedRow ( )
initExport() protected method

Initialize grid export.

protected void initExport ( )
throws Exception
initGridView() protected method

Initializes the Krajee GridView widget

protected void initGridView ( )
throws yii\base\InvalidConfigException
initLayout() protected method

Initialize the grid layout.

protected void initLayout ( )
throws yii\base\InvalidConfigException
initModule() protected method

Initialize the module based on module identifier

protected void initModule ( )
throws yii\base\InvalidConfigException
initPanel() protected method

Initializes and sets the grid panel layout based on the template and $panel settings.

protected void initPanel ( )
throws Exception
initPjaxContainerId() public method

Initializes pjax container identifier

public void initPjaxContainerId ( )
initToggleData() protected method

Initialize toggle data button options.

protected void initToggleData ( )
throws Exception
parseExportConfig() protected static method

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

parseKey() public static method

Parses the key and returns parsed key value as string based on the data type

public static string parseKey ( $key )
$key mixed
prepareGridView() protected method

Prepares the Krajee GridView widget for run

protected void prepareGridView ( )
throws yii\base\InvalidConfigException
registerAssets() protected method

Registers client assets for the kartik\grid\GridView widget.

protected void registerAssets ( )
throws Exception
renderExport() public method

Renders the export menu.

public string renderExport ( )
throws yii\base\InvalidConfigException
throws Exception
renderPageSummary() public method

Renders the table page summary.

public string renderPageSummary ( )
return string

The rendering result.

throws Exception
renderTablePart() protected method

Renders the table header or footer part

protected string renderTablePart ( $part, $content )
$part string

Whether thead or tfoot

$content string
throws Exception
renderTableRow() public method

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

renderToggleData() public method

Renders the toggle data button.

public string renderToggleData ( )
throws Exception
renderToolbar() protected method

Generates the toolbar.

protected string renderToolbar ( )
throws Exception
renderToolbarContainer() protected method

Generates the toolbar container with the toolbar

protected void renderToolbarContainer ( )
throws Exception
replaceLayoutTokens() protected method

Replace layout tokens

protected void replaceLayoutTokens ( $pairs )
$pairs array

The token to find and its replaced value as key value pairs

setPagerOptionClass() protected method

Adds CSS class to the pager parameter

protected void setPagerOptionClass ( $param, $css )
$param string

The pager param

$css string

The CSS class

throws Exception