mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 02:13:17 +08:00
Merge pull request #2891 from johonunu/summaryOptions-emptyTextOptions-BaseListView
Added summaryOptions and emptyTextOptions to BaseListView
This commit is contained in:
@ -178,6 +178,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh: LinkPager can now register relational link tags in the html header for prev, next, first and last page (cebe)
|
- Enh: LinkPager can now register relational link tags in the html header for prev, next, first and last page (cebe)
|
||||||
- Enh: Added `yii\web\UrlRuleInterface` and `yii\web\CompositeUrlRule` (qiangxue)
|
- Enh: Added `yii\web\UrlRuleInterface` and `yii\web\CompositeUrlRule` (qiangxue)
|
||||||
- Enh: Added `yii\web\Request::getAuthUser()` and `getAuthPassword()` (qiangxue)
|
- Enh: Added `yii\web\Request::getAuthUser()` and `getAuthPassword()` (qiangxue)
|
||||||
|
- Enh: Added summaryOptions and emptyTextOptions to BaseListView (johonunu)
|
||||||
- Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe)
|
- Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe)
|
||||||
- Chg #735: Added back `ActiveField::hiddenInput()` (qiangxue)
|
- Chg #735: Added back `ActiveField::hiddenInput()` (qiangxue)
|
||||||
- Chg #1186: Changed `Sort` to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
|
- Chg #1186: Changed `Sort` to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
|
||||||
|
|||||||
@ -53,6 +53,12 @@ abstract class BaseListView extends Widget
|
|||||||
* - `{pageCount}`: the number of pages available
|
* - `{pageCount}`: the number of pages available
|
||||||
*/
|
*/
|
||||||
public $summary;
|
public $summary;
|
||||||
|
/**
|
||||||
|
* @var array the HTML attributes for the summary of the list view.
|
||||||
|
* The "tag" element specifies the tag name of the summary element and defaults to "div".
|
||||||
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
|
||||||
|
*/
|
||||||
|
public $summaryOptions = ['class' => 'summary'];
|
||||||
/**
|
/**
|
||||||
* @var boolean whether to show the list view if [[dataProvider]] returns no data.
|
* @var boolean whether to show the list view if [[dataProvider]] returns no data.
|
||||||
*/
|
*/
|
||||||
@ -61,6 +67,12 @@ abstract class BaseListView extends Widget
|
|||||||
* @var string the HTML content to be displayed when [[dataProvider]] does not have any data.
|
* @var string the HTML content to be displayed when [[dataProvider]] does not have any data.
|
||||||
*/
|
*/
|
||||||
public $emptyText;
|
public $emptyText;
|
||||||
|
/**
|
||||||
|
* @var array the HTML attributes for the emptyText of the list view.
|
||||||
|
* The "tag" element specifies the tag name of the emptyText element and defaults to "div".
|
||||||
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
|
||||||
|
*/
|
||||||
|
public $emptyTextOptions = ['class' => 'empty'];
|
||||||
/**
|
/**
|
||||||
* @var string the layout that determines how different sections of the list view should be organized.
|
* @var string the layout that determines how different sections of the list view should be organized.
|
||||||
* The following tokens will be replaced with the corresponding section contents:
|
* The following tokens will be replaced with the corresponding section contents:
|
||||||
@ -139,7 +151,8 @@ abstract class BaseListView extends Widget
|
|||||||
*/
|
*/
|
||||||
public function renderEmpty()
|
public function renderEmpty()
|
||||||
{
|
{
|
||||||
return '<div class="empty">' . ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText) . '</div>';
|
$tag = ArrayHelper::remove($this->emptyTextOptions, 'tag', 'div');
|
||||||
|
return Html::tag($tag, ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText), $this->emptyTextOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,6 +164,7 @@ abstract class BaseListView extends Widget
|
|||||||
if ($count <= 0) {
|
if ($count <= 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
$tag = ArrayHelper::remove($this->summaryOptions, 'tag', 'div');
|
||||||
if (($pagination = $this->dataProvider->getPagination()) !== false) {
|
if (($pagination = $this->dataProvider->getPagination()) !== false) {
|
||||||
$totalCount = $this->dataProvider->getTotalCount();
|
$totalCount = $this->dataProvider->getTotalCount();
|
||||||
$begin = $pagination->getPage() * $pagination->pageSize + 1;
|
$begin = $pagination->getPage() * $pagination->pageSize + 1;
|
||||||
@ -161,29 +175,27 @@ abstract class BaseListView extends Widget
|
|||||||
$page = $pagination->getPage() + 1;
|
$page = $pagination->getPage() + 1;
|
||||||
$pageCount = $pagination->pageCount;
|
$pageCount = $pagination->pageCount;
|
||||||
if (($summaryContent = $this->summary) === null) {
|
if (($summaryContent = $this->summary) === null) {
|
||||||
return '<div class="summary">'
|
return Html::tag($tag, Yii::t('yii', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.', [
|
||||||
. Yii::t('yii', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.', [
|
|
||||||
'begin' => $begin,
|
'begin' => $begin,
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
'totalCount' => $totalCount,
|
'totalCount' => $totalCount,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
])
|
]), $this->summaryOptions);
|
||||||
. '</div>';
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$begin = $page = $pageCount = 1;
|
$begin = $page = $pageCount = 1;
|
||||||
$end = $totalCount = $count;
|
$end = $totalCount = $count;
|
||||||
if (($summaryContent = $this->summary) === null) {
|
if (($summaryContent = $this->summary) === null) {
|
||||||
return '<div class="summary">' . Yii::t('yii', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.', [
|
return Html::tag($tag, Yii::t('yii', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.', [
|
||||||
'begin' => $begin,
|
'begin' => $begin,
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
'totalCount' => $totalCount,
|
'totalCount' => $totalCount,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
]) . '</div>';
|
]), $this->summaryOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user