* @link http://www.yiiframework.com/ * @copyright Copyright © 2008-2011 Yii Software LLC * @license http://www.yiiframework.com/license/ */ Yii::import('zii.widgets.CBaseListView'); Yii::import('zii.widgets.grid.CDataColumn'); Yii::import('zii.widgets.grid.CLinkColumn'); Yii::import('zii.widgets.grid.CButtonColumn'); Yii::import('zii.widgets.grid.CCheckBoxColumn'); /** * CGridView displays a list of data items in terms of a table. * * Each row of the table represents the data of a single data item, and a column usually represents * an attribute of the item (some columns may correspond to complex expression of attributes or static text). * * CGridView supports both sorting and pagination of the data items. The sorting * and pagination can be done in AJAX mode or normal page request. A benefit of using CGridView is that * when the user browser disables JavaScript, the sorting and pagination automatically degenerate * to normal page requests and are still functioning as expected. * * CGridView should be used together with a {@link IDataProvider data provider}, preferrably a * {@link CActiveDataProvider}. * * The minimal code needed to use CGridView is as follows: * *
* $dataProvider=new CActiveDataProvider('Post');
*
* $this->widget('zii.widgets.grid.CGridView', array(
* 'dataProvider'=>$dataProvider,
* ));
*
*
* The above code first creates a data provider for the Post ActiveRecord class.
* It then uses CGridView to display every attribute in every Post instance.
* The displayed table is equiped with sorting and pagination functionality.
*
* In order to selectively display attributes with different formats, we may configure the
* {@link CGridView::columns} property. For example, we may specify only the title
* and create_time attributes to be displayed, and the create_time
* should be properly formatted to show as a time. We may also display the attributes of the related
* objects using the dot-syntax as shown below:
*
*
* $this->widget('zii.widgets.grid.CGridView', array(
* 'dataProvider'=>$dataProvider,
* 'columns'=>array(
* 'title', // display the 'title' attribute
* 'category.name', // display the 'name' attribute of the 'category' relation
* 'content:html', // display the 'content' attribute as purified HTML
* array( // display 'create_time' using an expression
* 'name'=>'create_time',
* 'value'=>'date("M j, Y", $data->create_time)',
* ),
* array( // display 'author.username' using an expression
* 'name'=>'authorName',
* 'value'=>'$data->author->username',
* ),
* array( // display a column with "view", "update" and "delete" buttons
* 'class'=>'CButtonColumn',
* ),
* ),
* ));
*
*
* Please refer to {@link columns} for more details about how to configure this property.
*
* @property boolean $hasFooter Whether the table should render a footer.
* This is true if any of the {@link columns} has a true {@link CGridColumn::hasFooter} value.
* @property CFormatter $formatter The formatter instance. Defaults to the 'format' application component.
*
* @author Qiang Xue array('odd', 'even').
* @see rowCssClassExpression
*/
public $rowCssClass=array('odd','even');
/**
* @var string a PHP expression that is evaluated for every table body row and whose result
* is used as the CSS class name for the row. In this expression, the variable $row
* stands for the row number (zero-based), $data is the data model associated with
* the row, and $this is the grid object.
* @see rowCssClass
*/
public $rowCssClassExpression;
/**
* @var boolean whether to display the table even when there is no data. Defaults to true.
* The {@link emptyText} will be displayed to indicate there is no data.
*/
public $showTableOnEmpty=true;
/**
* @var mixed the ID of the container whose content may be updated with an AJAX response.
* Defaults to null, meaning the container for this grid view instance.
* If it is set false, it means sorting and pagination will be performed in normal page requests
* instead of AJAX requests. If the sorting and pagination should trigger the update of multiple
* containers' content in AJAX fashion, these container IDs may be listed here (separated with comma).
*/
public $ajaxUpdate;
/**
* @var string the jQuery selector of the HTML elements that may trigger AJAX updates when they are clicked.
* If not set, the pagination links and the sorting links will trigger AJAX updates.
* @since 1.1.7
*/
public $updateSelector;
/**
* @var string a javascript function that will be invoked if an AJAX update error occurs.
*
* The function signature is function(xhr, textStatus, errorThrown, errorMessage)
* xhr is the XMLHttpRequest object.textStatus is a string describing the type of error that occurred.
* Possible values (besides null) are "timeout", "error", "notmodified" and "parsererror"errorThrown is an optional exception object, if one occurred.errorMessage is the CGridView default error message derived from xhr and errorThrown.
* Usefull if you just want to display this error differently. CGridView by default displays this error with an javascript.alert()
* ...
* 'ajaxUpdateError'=>'function(xhr,ts,et,err){ $("#myerrordiv").text(err); }',
* ...
*
*/
public $ajaxUpdateError;
/**
* @var string the name of the GET variable that indicates the request is an AJAX request triggered
* by this widget. Defaults to 'ajax'. This is effective only when {@link ajaxUpdate} is not false.
*/
public $ajaxVar='ajax';
/**
* @var mixed the URL for the AJAX requests should be sent to. {@link CHtml::normalizeUrl()} will be
* called on this property. If not set, the current page URL will be used for AJAX requests.
* @since 1.1.8
*/
public $ajaxUrl;
/**
* @var string a javascript function that will be invoked before an AJAX update occurs.
* The function signature is function(id,options) where 'id' refers to the ID of the grid view,
* 'options' the AJAX request options (see jQuery.ajax api manual).
*/
public $beforeAjaxUpdate;
/**
* @var string a javascript function that will be invoked after a successful AJAX response is received.
* The function signature is function(id, data) where 'id' refers to the ID of the grid view,
* 'data' the received ajax response data.
*/
public $afterAjaxUpdate;
/**
* @var string a javascript function that will be invoked after the row selection is changed.
* The function signature is function(id) where 'id' refers to the ID of the grid view.
* In this function, you may use $.fn.yiiGridView.getSelection(id) to get the key values
* of the currently selected rows.
* @see selectableRows
*/
public $selectionChanged;
/**
* @var integer the number of table body rows that can be selected. If 0, it means rows cannot be selected.
* If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected.
* A selected row will have a CSS class named 'selected'. You may also call the JavaScript function
* $.fn.yiiGridView.getSelection(containerID) to retrieve the key values of the selected rows.
*/
public $selectableRows=1;
/**
* @var string the base script URL for all grid view resources (eg javascript, CSS file, images).
* Defaults to null, meaning using the integrated grid view resources (which are published as assets).
*/
public $baseScriptUrl;
/**
* @var string the URL of the CSS file used by this grid view. Defaults to null, meaning using the integrated
* CSS file. If this is set false, you are responsible to explicitly include the necessary CSS file in your page.
*/
public $cssFile;
/**
* @var string the text to be displayed in a data cell when a data value is null. This property will NOT be HTML-encoded
* when rendering. Defaults to an HTML blank.
*/
public $nullDisplay=' ';
/**
* @var string the text to be displayed in an empty grid cell. This property will NOT be HTML-encoded when rendering. Defaults to an HTML blank.
* This differs from {@link nullDisplay} in that {@link nullDisplay} is only used by {@link CDataColumn} to render
* null data values.
* @since 1.1.7
*/
public $blankDisplay=' ';
/**
* @var string the CSS class name that will be assigned to the widget container element
* when the widget is updating its content via AJAX. Defaults to 'grid-view-loading'.
* @since 1.1.1
*/
public $loadingCssClass='grid-view-loading';
/**
* @var string the CSS class name for the table row element containing all filter input fields. Defaults to 'filters'.
* @see filter
* @since 1.1.1
*/
public $filterCssClass='filters';
/**
* @var string whether the filters should be displayed in the grid view. Valid values include:
*