Class kartik\grid\GridView
Inheritance | kartik\grid\GridView » yii\grid\GridView » yii\widgets\BaseListView » yii\base\Widget » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | kartik\base\BootstrapInterface, kartik\grid\GridViewInterface, yii\base\Configurable, yii\base\ViewContextInterface |
Uses Traits | kartik\base\BootstrapTrait, kartik\grid\GridViewTrait |
Subclasses | kartik\export\ExportMenu |
Available since version | 1.0 |
The GridView widget is used to display data in a grid. It provides features like sorting, paging and also filtering the data. The kartik\grid\GridView widget extends and modifies yii\grid\GridView with various new enhancements.
The columns of the grid are configured in terms of yii\grid\Column classes, which are configured via $columns. The look and feel of a grid view can be customized using the large amount of properties.
The GridView is available and configurable as part of the Krajee grid kartik\grid\Module with various new additional grid columns and enhanced settings. The extension also incorporates various Bootstrap 3.x styling options, inbuilt additional jQuery plugins and has embedded support for Pjax based rendering.
A basic usage of the widget looks like the following:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id',
'name',
'created_at:datetime',
// ...
]
]) ?>
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 |
$afterRow | Closure | An anonymous function that is called once AFTER rendering each data model. | yii\grid\GridView |
$autoIdPrefix | string | The prefix to the automatically generated widget IDs. | yii\base\Widget |
$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 |
$beforeRow | Closure | An anonymous function that is called once BEFORE rendering each data model. | yii\grid\GridView |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. | yii\base\Component |
$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 |
$bsColCssPrefixes | array | The bootstrap grid column css prefixes mapping, the key is the bootstrap versions, and the value is an array containing the sizes and their corresponding grid column css prefixes. | kartik\base\BootstrapTrait |
$bsCssMap | array | CSS conversion mappings across bootstrap library versions. | kartik\base\BootstrapTrait |
$bsExtBasename | integer | The yii2 bootstrap extension base name (readonly property available via getter method getBsExtBasename()) | kartik\base\BootstrapTrait |
$bsVer | integer | Bootstrap version number currently set (readonly property available via getter method getBsVer()) | kartik\base\BootstrapTrait |
$bsVersion | integer|string | The bootstrap library version that you wish to use for this specific extension / widget. | kartik\base\BootstrapTrait |
$caption | string | The caption of the grid table | yii\grid\GridView |
$captionOptions | array | The HTML attributes for the grid caption | kartik\grid\GridView |
$columns | array | Grid column configuration. | yii\grid\GridView |
$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 |
$counter | integer | A counter used to generate $id for widgets. | yii\base\Widget |
$dataColumnClass | string | The default data column class if the class name is not explicitly specified when configuring a data column. | kartik\grid\GridView |
$dataProvider | yii\data\DataProviderInterface | The data provider for the view. | yii\widgets\BaseListView |
$defaultBtnCss | string | Default bootstrap button CSS (readonly property available via getter method getDefaultBtnCss()) | kartik\base\BootstrapTrait |
$defaultIconPrefix | string | Default icon prefix (readonly property available via getter method getDefaultIconPrefix()) | kartik\base\BootstrapTrait |
$defaultPagination | string | The default pagination that will be read by toggle data. | kartik\grid\GridViewTrait |
$dropdownClass | string | Bootstrap dropdown class name based on currently configured bootstrap version (readonly property available via getter method getDropdownClass()) | kartik\base\BootstrapTrait |
$editedRowConfig | array | The configuration for the row being currently edited | kartik\grid\GridViewTrait |
$emptyCell | string | The HTML display when the content of a cell is empty. | yii\grid\GridView |
$emptyText | string|false | The HTML content to be displayed when $dataProvider does not have any data. | yii\widgets\BaseListView |
$emptyTextOptions | array | The HTML attributes for the emptyText of the list view. | yii\widgets\BaseListView |
$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 |
$filterErrorOptions | array | The options for rendering every filter error message. | yii\grid\GridView |
$filterErrorSummaryOptions | array | The options for rendering the filter error summary. | yii\grid\GridView |
$filterModel | yii\base\Model|null | The model that keeps the user-entered filter data. | yii\grid\GridView |
$filterOnFocusOut | boolean | Whatever to apply filters on losing focus. | yii\grid\GridView |
$filterPosition | string | Whether the filters should be displayed in the grid view. | yii\grid\GridView |
$filterRowOptions | array | The HTML attributes for the filter row element. | yii\grid\GridView |
$filterSelector | string | Additional jQuery selector for selecting filter input fields | yii\grid\GridView |
$filterUrl | string|array|null | The URL for returning the filtering result. | yii\grid\GridView |
$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 |
$footerRowOptions | array | The HTML attributes for the table footer row. | yii\grid\GridView |
$formatter | array|yii\i18n\Formatter|null | The formatter used to format model attribute values into displayable texts. | yii\grid\GridView |
$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 |
$headerRowOptions | array | The HTML attributes for the table header row. | yii\grid\GridView |
$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 |
$id | string|null | ID of the widget. Note that the type of this property differs in getter and setter. See getId() and setId() for details. | yii\base\Widget |
$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 |
$options | array | The HTML attributes for the container tag of the grid view. | yii\grid\GridView |
$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 | ||
$pager | array | The configuration for the pager widget. | yii\widgets\BaseListView |
$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 |
$pjaxContainerId | string | kartik\grid\GridViewTrait | |
$pjaxSettings | array | The pjax settings for the widget. | kartik\grid\GridViewTrait |
$placeFooterAfterBody | boolean | Whether to place footer after body in DOM if $showFooter is true | yii\grid\GridView |
$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 |
$rowOptions | array|Closure | The HTML attributes for the table body rows. | yii\grid\GridView |
$showFooter | boolean | Whether to show the footer section of the grid table. | yii\grid\GridView |
$showHeader | boolean | Whether to show the header section of the grid table. | yii\grid\GridView |
$showOnEmpty | boolean | Whether to show the grid view if $dataProvider returns no data. | yii\grid\GridView |
$showPageSummary | boolean | Whether to show the page summary row for the table. | kartik\grid\GridViewTrait |
$sorter | array | The configuration for the sorter widget. | yii\widgets\BaseListView |
$sorterIcons | array | The configuration for sorter icons. | kartik\grid\GridViewTrait |
$stack | yii\base\Widget[] | The widgets that are currently being rendered (not ended). | yii\base\Widget |
$striped | boolean | Whether the grid will have a striped style. |
kartik\grid\GridViewTrait |
$summary | string | The HTML content to be displayed as the summary of the list view. | yii\widgets\BaseListView |
$summaryOptions | array | The HTML attributes for the summary of the list view. | yii\widgets\BaseListView |
$tableOptions | array | The HTML attributes for the grid element | kartik\grid\GridView |
$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 |
$view | yii\web\View | The view object that can be used to render views or view files. Note that the type of this property differs in getter and setter. See getView() and setView() for details. | yii\base\Widget |
$viewPath | string | The directory containing the view files for this widget. | yii\base\Widget |
Protected Properties
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
addCssClass() | Adds bootstrap CSS class to options by parsing the bootstrap version for the specified Bootstrap CSS type. | kartik\base\BootstrapTrait |
afterRun() | This method is invoked right after a widget is executed. | yii\base\Widget |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
beforeRun() | This method is invoked right before the widget is executed. | yii\base\Widget |
begin() | Begins a widget. | yii\base\Widget |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
end() | Ends a widget. | yii\base\Widget |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getBSClass() | Gets the respective Bootstrap class based on currently configured bootstrap version. | kartik\base\BootstrapTrait |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getBsVer() | Gets the current set bootstrap version number. | kartik\base\BootstrapTrait |
getCssClass() | Gets bootstrap css class by parsing the bootstrap version for the specified BS CSS type. | kartik\base\BootstrapTrait |
getDefaultBtnCss() | Gets the default button CSS | kartik\base\BootstrapTrait |
getDefaultIconPrefix() | Gets the default icon css prefix | kartik\base\BootstrapTrait |
getDefaultSorterIcons() | Gets default sorter icons | kartik\grid\GridViewTrait |
getDropdownClass() | Gets the respective bootstrap dropdown class name based on currently configured bootstrap version. | kartik\base\BootstrapTrait |
getId() | Returns the ID of the widget. | yii\base\Widget |
getPjaxContainerId() | Get pjax container identifier | kartik\grid\GridViewTrait |
getView() | Returns the view object that can be used to render views or view files. | yii\base\Widget |
getViewPath() | Returns the directory containing the view files for this widget. | yii\base\Widget |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the grid view. | kartik\grid\GridView |
initPjaxContainerId() | Initializes pjax container identifier | kartik\grid\GridViewTrait |
isBs() | Validate Bootstrap version | kartik\base\BootstrapTrait |
isBs4() | Validate if Bootstrap 4.x version. | kartik\base\BootstrapTrait |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
parseKey() | Parses the key and returns parsed key value as string based on the data type | kartik\grid\GridViewTrait |
removeCssClass() | Removes bootstrap CSS class from options by parsing the bootstrap version for the specified Bootstrap CSS type. | kartik\base\BootstrapTrait |
render() | Renders a view. | yii\base\Widget |
renderCaption() | Renders the caption element. | yii\grid\GridView |
renderColumnGroup() | Renders the column group HTML. | kartik\grid\GridView |
renderEmpty() | Renders the HTML content indicating that the list view has no data. | yii\widgets\BaseListView |
renderErrors() | Renders validator errors of filter model. | yii\grid\GridView |
renderExport() | Renders the export menu. | kartik\grid\GridViewTrait |
renderFile() | Renders a view file. | yii\base\Widget |
renderFilters() | Renders the filter. | yii\grid\GridView |
renderItems() | Renders the data models for the grid view. | yii\grid\GridView |
renderPageSummary() | Renders the table page summary. | kartik\grid\GridViewTrait |
renderPager() | Renders the pager. | yii\widgets\BaseListView |
renderSection() | Renders a section of the specified name. | yii\grid\GridView |
renderSorter() | Renders the sorter. | yii\widgets\BaseListView |
renderSummary() | Renders the summary text. | kartik\grid\GridView |
renderTableBody() | Renders the table body. | kartik\grid\GridView |
renderTableFooter() | Renders the table footer. | kartik\grid\GridView |
renderTableHeader() | Renders the table header. | kartik\grid\GridView |
renderTableRow() | Renders a table row with the given data model and key. | kartik\grid\GridViewTrait |
renderToggleData() | Renders the toggle data button. | kartik\grid\GridViewTrait |
run() | Runs the widget. | kartik\grid\GridView |
setId() | Sets the ID of the widget. | yii\base\Widget |
setView() | Sets the view object to be used by this widget. | yii\base\Widget |
trigger() | Triggers an event. | yii\base\Component |
widget() | Creates a widget instance and runs it. | yii\base\Widget |
Protected Methods
Method | Description | Defined By |
---|---|---|
beginPjax() | Begins the pjax widget rendering | kartik\grid\GridViewTrait |
configureBsVersion() | Configures the bootstrap version settings | kartik\base\BootstrapTrait |
createDataColumn() | Creates a yii\grid\DataColumn object based on a string in the format of "attribute:format:label". | yii\grid\GridView |
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 |
getBsExtBasename() | The yii2-bootstrap extension base name. | kartik\base\BootstrapTrait |
getClientOptions() | Returns the options for the grid view JS widget. | yii\grid\GridView |
getPageSummaryRow() | Get the page summary row markup | kartik\grid\GridViewTrait |
guessColumns() | This function tries to guess the columns to show from the given data if $columns are not explicitly specified. | yii\grid\GridView |
initBootstrapStyle() | Initialize bootstrap specific styling. | kartik\grid\GridViewTrait |
initBsVersion() | Initializes bootstrap versions for the widgets and asset bundles. | kartik\base\BootstrapTrait |
initColumns() | Creates column objects and initializes them. | yii\grid\GridView |
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 |
isSameVersion() | Compares two versions and checks if they are of the same major BS version. | kartik\base\BootstrapTrait |
parseExportConfig() | Parses export configuration and returns the merged defaults. | kartik\grid\GridViewTrait |
parseVer() | Parses and returns the major BS version | kartik\base\BootstrapTrait |
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 |
Events
Event | Type | Description | Defined By |
---|---|---|---|
EVENT_AFTER_RUN | yii\base\WidgetEvent | An event raised right after executing a widget. (available since version 2.0.11) | yii\base\Widget |
EVENT_BEFORE_RUN | yii\base\WidgetEvent | An event raised right before executing a widget. (available since version 2.0.11) | yii\base\Widget |
EVENT_INIT | yii\base\Event | An event that is triggered when the widget is initialized via init(). (available since version 2.0.11) | yii\base\Widget |
Constants
Constant | Value | Description | Defined By |
---|---|---|---|
FILTER_POS_BODY | 'body' | yii\grid\GridView | |
FILTER_POS_FOOTER | 'footer' | yii\grid\GridView | |
FILTER_POS_HEADER | 'header' | yii\grid\GridView |
Property Details
The HTML attributes for the grid caption
The default data column class if the class name is not explicitly specified when configuring a data column. Defaults to 'kartik\grid\DataColumn'.
The HTML attributes for the grid element
Method Details
Initializes the grid view.
This method will initialize required property values and instantiate $columns objects.
public void init ( ) |
Renders the column group HTML.
public boolean|string renderColumnGroup ( ) | ||
return | boolean|string | The column group HTML or |
---|
Renders the summary text.
public void renderSummary ( ) |
Renders the table body.
public string renderTableBody ( ) | ||
return | string | The rendering result. |
---|---|---|
throws | yii\base\InvalidConfigException |
Renders the table footer.
public string renderTableFooter ( ) | ||
return | string | The rendering result. |
---|
Renders the table header.
public string renderTableHeader ( ) | ||
return | string | The rendering result. |
---|
Runs the widget.
public void run ( ) |