'card']; /** * @var array table的html属性 */ public $tableOptions = ['class' => 'table table-bordered table-striped dataTable']; /** * @var array 表格头部html属性 */ public $headerRowOptions = []; /** * @var array 表格脚部html属性 */ public $footerRowOptions = []; /** * @var array|Cloure 表格每一行的html属性 * 这个参数除了可以是一个options数组外,还可以是一个匿名函数,该函数必须返回一个options数组, * 渲染每一行都会调用该函数 * 该函数必须遵循以下声明规则 * ```php * function ($model, $key, $index, $grid) * ``` * * - `$model`: 每行的模型 * - `$key`: id值 * - `$index`: [[dataProvider]]提供的索引号 * - `$grid`: GridView 对象 */ public $rowOptions = []; /** * @var Closure an 一个匿名函数(结构和[[rowOptions]]一样),每行渲染前后都会被调用 */ public $beforeRow; public $afterRow; /** * @var bool 是否显示表格头 */ public $showHeader = true; /** * @var bool 是否显示表格脚 */ public $showFooter = false; /** * @var bool 没有数据情况下是否显示 */ public $showOnEmpty = true; /** * @var array|Formatter 用来格式化输出属性值 */ public $formatter; /** * @var string 摘要的显示样式 * * * - `{begin}`: 开始条数 * - `{end}`: 结束条数 * - `{count}`: 显示条数 * - `{totalCount}`: 总记录条数 * - `{page}`: 显示分页 * - `{pageCount}`: 总分页数 * - `{select}`: 显示页数 */ public $summary = "{select} 显示{begin}~{end}条 共{totalCount}条"; /** * @var array 摘要的html属性 */ public $summaryOptions = ['class' => 'summary']; /** * @var array 列配置数组. 数组每一项代表一个列,列数组可以包括class、attribute、format、label等。 * 例子: * ```php * [ * ['class' => SerialColumn::className()], * [ * 'class' => DataColumn::className(), //渲染用到的类,没一列都默认使用[[DataColumn]]渲染,所以这里可以忽略 * 'attribute' => 'name', //代表每一行的数据原 * 'format' => 'text', //输出的格式 * 'label' => 'Name', //label * '' => '' * ], * ['class' => CheckboxColumn::className()], * ] * ``` * * 当然,也支持简写成这样:[[DataColumn::attribute|attribute]], [[DataColumn::format|format]], * 或 [[DataColumn::label|label]] options: `"attribute:format:label"`. * 所以上面例子的 "name" 列能简写成这样 : `"name:text:Name"`. * 甚至"format"和"label"都是可以不制定的,因为它们都有默认值。 * * 其实大多数情况下都可以使用简写: * * ```php * [ * 'id', * 'amount:currency:Total Amount', * 'created_at:datetime', * ] * ``` * * 当[[dataProvider]]提供active records, 且active record又和其它 active record建立了关联关系的, * 例如 the `name` 属性是 和 `author` 关联,那么你可以这样制定数据: * * ```php * // shortcut syntax * 'author.name', * // full syntax * [ * 'attribute' => 'author.name', * // ... * ] * ``` */ public $columns = []; /** * @var string 当单元格数据为空时候显示的内容。 */ public $emptyCell = ' '; /** * @var string TODO:这个目前用来做页数选择,具体原理没有研究清楚 */ public $filterSelector = 'select[name="per-page"]'; /** * @var type */ public $filter; /** * @var array 批量操作的选项 */ public $batch; /** * @var string 表格的layout: * * - `{summary}`: 摘要. * - `{items}`: 表格项. * - `{pager}`: 分页. * - `{batch}`: 批量处理 */ public $layout = <<< HTML
{batch} 添加
{filter}
{items}
{summary}
{pager}
HTML; public $batchTemplate = <<< HTML
HTML; /** * 初始化 grid view. * 初始化必须的属性和每个列对象 * @return */ public function init() { parent::init(); if ($this->formatter === null) { $this->formatter = Yii::$app->getFormatter(); } elseif (is_array($this->formatter)) { $this->formatter = Yii::createObject($this->formatter); } if (!$this->formatter instanceof Formatter) { throw new InvalidConfigException('The "formatter" property must be either a Format object or a configuration array.'); } $this->pager = [ 'options'=>['class'=>['justify-content-end','pagination']], 'linkOptions'=>['class'=>'page-link'], 'pageCssClass'=>'paginate_button page-item', 'disabledPageCssClass'=>'page-link disabled', 'firstPageLabel'=>'«', 'prevPageLabel'=>'‹', 'nextPageLabel'=>'›', 'lastPageLabel'=>'»',]; $this->initColumns(); } public function run() { $view = $this->getView(); GridViewAsset::register($view); $this->registerGridJs(); $this->registerIcheckJs(); $this->registerConfirmJs(); $this->registerExportJs(); parent::run(); } /** * 注册GridView Js */ protected function registerGridJs() { $options = Json::htmlEncode(['filterUrl' => Url::to(Yii::$app->request->url), 'filterSelector' => $this->filterSelector]); $id = $this->options['id']; $this->getView()->registerJs("jQuery('#$id').yiiGridView($options);"); } /** * 注册icheck Js */ protected function registerIcheckJs() { $js = <<