GridView
API reference › Debug › widgets › GridView
Renders a debugger grid whose footer sentence comes from the shared GridCount renderer.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$afterRow | Closure | An anonymous function that is called once AFTER rendering each data model. Default: null. | yii\ |
$autoIdPrefix static | string | The prefix to the automatically generated widget IDs. Default: 'w'. | yii\ |
$beforeRow | Closure | An anonymous function that is called once BEFORE rendering each data model. Default: null. | yii\ |
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$caption | string | The caption of the grid table Default: null. | yii\ |
$captionOptions | array | The HTML attributes for the caption element. Default: []. | yii\ |
$clientScript | array|yii\| | Client script class to use for client-side validation. Default: null. | yii\ |
$columns | array | Grid column configuration. Default: []. | yii\ |
$dataColumnClass | string | The default data column class if the class name is not explicitly specified when configuring a data column. Default: null. | yii\ |
$dataProvider | yii\ | The data provider for the view. Default: null. | yii\ |
$emptyCell | string | The HTML display when the content of a cell is empty. Default: ' '. | yii\ |
$emptyText | string| | The HTML content to be displayed when $dataProvider does not have any data. Default: null. | yii\ |
$emptyTextOptions | array | The HTML attributes for the emptyText of the list view. Default: ['class' => 'empty']. | yii\ |
$filterErrorOptions | array | The options for rendering every filter error message. Default: ['class' => 'field-error']. | yii\ |
$filterErrorSummaryOptions | array | The options for rendering the filter error summary. Default: ['class' => 'error-summary']. | yii\ |
$filterModel | yii\| | The model that keeps the user-entered filter data. Default: null. | yii\ |
$filterOnFocusOut | bool | Whatever to apply filters on losing focus. Default: true. Available since 2.0.16. | yii\ |
$filterPosition | string | Whether the filters should be displayed in the grid view. Default: self::FILTER_POS_BODY. | yii\ |
$filterRowOptions | array | The HTML attributes for the filter row element. Default: ['class' => 'filters']. | yii\ |
$filterSelector | string|Closure(string, | JQuery selector for selecting filter input fields. Default: null. | yii\ |
$filterUrl | string| | The URL for returning the filtering result. Url::to() will be called to normalize the URL. Default: null. | yii\ |
$footerRowOptions | array | The HTML attributes for the table footer row. Default: []. | yii\ |
$formatter | array|yii\| | The formatter used to format model attribute values into displayable texts. Default: null. | yii\ |
$headerRowOptions | array | The HTML attributes for the table header row. Default: []. | yii\ |
$id | string | Id of the widget. | yii\ |
$layout | string | The layout that determines how different sections of the grid view should be organized. Default: "{summary}\. | yii\ |
$options | array | The HTML attributes for the container tag of the grid view. Default: ['class' => 'grid-view']. | yii\ |
$overrideFilterSelector | bool | If set, $filterSelector overrides the default selector of ’#$id input, #$id select’ (where $id is the filter row ID) rather than being added to it. Default: false. | yii\ |
$pager | array | The configuration for the pager widget. Default: []. | yii\ |
$placeFooterAfterBody | bool | Whether to place footer after body in DOM if $showFooter is true Default: false. Available since 2.0.14. | yii\ |
$rowOptions | array|Closure | The HTML attributes for the table body rows. Default: []. | yii\ |
$showFooter | bool | Whether to show the footer section of the grid table. Default: false. | yii\ |
$showHeader | bool | Whether to show the header section of the grid table. Default: true. | yii\ |
$showOnEmpty | bool | Whether to show the grid view if $dataProvider returns no data. Default: true. | yii\ |
$sorter | array | The configuration for the sorter widget. Default: []. | yii\ |
$summary | string| | The HTML content to be displayed as the summary of the list view. Default: null. | yii\ |
$summaryOptions | array | The HTML attributes for the summary of the list view. Default: ['class' => 'summary']. | yii\ |
$tableOptions | array | The HTML attributes for the grid table element. Default: []. | yii\ |
$view | yii\ | The view object that can be used to render views or view files. | yii\ |
$viewPath read-only | string | The directory containing the view files for this widget. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
afterRun() | This method is invoked right after a widget is executed. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
beforeRun() | This method is invoked right before the widget is executed. | yii\ |
begin() static | Begins a widget. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
end() static | Ends a widget. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getId() | Returns the ID of the widget. | yii\ |
getView() | Returns the view object that can be used to render views or view files. | yii\ |
getViewPath() | Returns the directory containing the view files for this widget. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the grid view. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
render() | Renders a view. | yii\ |
renderCaption() | Renders the caption element. | yii\ |
renderColumnGroup() | Renders the column group HTML. | yii\ |
renderEmpty() | Renders the HTML content indicating that the list view has no data. | yii\ |
renderErrors() | Renders validator errors of filter model. | yii\ |
renderFile() | Renders a view file. | yii\ |
renderFilters() | Renders the filter. | yii\ |
renderItems() | Renders the data models for the grid view. | yii\ |
renderPager() | Renders the pager. | yii\ |
renderSection() | Renders a section of the specified name. | yii\ |
renderSorter() | Renders the sorter. | yii\ |
renderSummary() | Renders the row-count sentence for the rows currently on screen. | GridView |
renderTableBody() | Renders the table body. | yii\ |
renderTableFooter() | Renders the table footer. | yii\ |
renderTableHeader() | Renders the table header. | yii\ |
renderTableRow() | Renders a table row with the given data model and key. | yii\ |
run() | Runs the widget. | yii\ |
setId() | Sets the ID of the widget. | yii\ |
setView() | Sets the view object to be used by this widget. | yii\ |
trigger() | Triggers an event. | yii\ |
widget() static | Creates a widget instance and runs it. | yii\ |
createDataColumn() protected | Creates a DataColumn object based on a string in the format of “attribute:format:label”. | yii\ |
getClientOptions() protected | Returns the options for the grid view JS widget. | yii\ |
guessColumns() protected | This function tries to guess the columns to show from the given data if $columns are not explicitly specified. | yii\ |
initColumns() protected | Creates column objects and initializes them. | yii\ |
Events
Section titled “Events”| Event | Type | Description | Defined by |
|---|---|---|---|
EVENT_INIT | yii\ | An event that is triggered when the widget is initialized via init(). Event name: 'init'. Available since 2.0.11. | yii\ |
EVENT_BEFORE_RUN | yii\ | An event raised right before executing a widget. Event name: 'beforeRun'. Available since 2.0.11. | yii\ |
EVENT_AFTER_RUN | yii\ | An event raised right after executing a widget. Event name: 'afterRun'. Available since 2.0.11. | yii\ |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
FILTER_POS_HEADER | 'header' | yii\ | |
FILTER_POS_FOOTER | 'footer' | yii\ | |
FILTER_POS_BODY | 'body' | yii\ |
Method details
Section titled “Method details”renderSummary()
Section titled “renderSummary() ”public function renderSummary(): stringRenders the row-count sentence for the rows currently on screen.
Derives the counters the way BaseListView::renderSummary() does: the paginator’s offset opens
the range and the number of rows rendered on the page closes it, while disabled pagination reports the whole set
as a single page. An empty page reports 0-0, matching the shared renderer instead of collapsing to an empty
string.
Returns
string: Rendered row-count sentence.