'fixed-table-header', 'style' => 'margin-right: 0px;'];
public $tableOptions = ['class' => 'table table-hover'];
public $layout = "{items}\n
";
public $pagerOptions = [
'firstPageLabel' => '首页',
'lastPageLabel' => '尾页',
'prevPageLabel' => '上一页',
'nextPageLabel' => '下一页',
'options' => [
'class' => 'pagination',
],
];
public $filterRow;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if( !$this->rowOptions && $this->rowOptions !== false ) {
$this->rowOptions = function ($model, $key, $index, $grid) {
if ($index % 2 === 0) {
return ['class' => 'odd'];
} else {
return ['class' => 'even'];
}
};
}
if( !$this->pagerOptions && $this->pagerOptions !== false ) {
$this->pagerOptions = [
'firstPageLabel' => Yii::t('app', 'first'),
'lastPageLabel' => Yii::t('app', 'last'),
'prevPageLabel' => Yii::t('app', 'previous'),
'nextPageLabel' => Yii::t('app', 'next'),
'options' => [
'class' => 'pagination',
]
];
}
}
/**
* @inheritdoc
*/
public function renderTableRow($model, $key, $index)
{
if ($this->filterRow !== null && call_user_func($this->filterRow, $model, $key, $index, $this) === false) {
return '';
}
return parent::renderTableRow($model, $key, $index);
}
/**
* @inheritdoc
*/
public function renderPager()
{
$pagination = $this->dataProvider->getPagination();
if ($pagination === false || $this->dataProvider->getCount() <= 0) {
return '';
}
/* @var $class LinkPager */
$pager = $this->pager;
$class = ArrayHelper::remove($pager, 'class', LinkPager::className());
$pager['pagination'] = $pagination;
$pager['view'] = $this->getView();
$pager = array_merge($pager, $this->pagerOptions);
return $class::widget($pager);
}
/**
* @inheritdoc
*/
public function run()
{
$id = $this->options['id'];
$options = Json::htmlEncode($this->getClientOptions());
$view = $this->getView();
GridViewAsset::register($view);
$view->registerJs("jQuery('#$id').yiiGridView($options);");
BaseListView::run();
}
}