Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
743d31a8
Commit
743d31a8
authored
Nov 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1075: separated empty switch and empty display for ListView and GridView.
parent
de062c26
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
9 deletions
+30
-9
GridView.php
framework/yii/grid/GridView.php
+9
-4
BaseListView.php
framework/yii/widgets/BaseListView.php
+21
-5
No files found.
framework/yii/grid/GridView.php
View file @
743d31a8
...
...
@@ -89,10 +89,9 @@ class GridView extends BaseListView
*/
public
$showFooter
=
false
;
/**
* @var string|boolean the HTML content to be displayed when [[dataProvider]] does not have any data.
* If false, the grid view will still be displayed (without body content though).
* @var boolean whether to show the grid view if [[dataProvider]] returns no data.
*/
public
$
empty
=
fals
e
;
public
$
showOnEmpty
=
tru
e
;
/**
* @var array|Formatter the formatter used to format model attribute values into displayable texts.
* This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]]
...
...
@@ -342,7 +341,13 @@ class GridView extends BaseListView
}
}
}
return
"<tbody>
\n
"
.
implode
(
"
\n
"
,
$rows
)
.
"
\n
</tbody>"
;
if
(
empty
(
$rows
))
{
return
"<tbody>
\n
"
.
implode
(
"
\n
"
,
$rows
)
.
"
\n
</tbody>"
;
}
else
{
$colspan
=
count
(
$this
->
columns
);
return
"<tbody>
\n
<tr><td colspan=
\"
$colspan
\"
>"
.
$this
->
renderEmpty
()
.
"</td></tr>
\n
</tbody>"
;
}
}
/**
...
...
framework/yii/widgets/BaseListView.php
View file @
743d31a8
...
...
@@ -53,10 +53,13 @@ abstract class BaseListView extends Widget
*/
public
$summary
;
/**
* @var string|boolean the HTML content to be displayed when [[dataProvider]] does not have any data.
* If false, the list view will still be displayed (without body content though).
* @var boolean whether to show the list view if [[dataProvider]] returns no data.
*/
public
$empty
;
public
$showOnEmpty
=
false
;
/**
* @var string the HTML content to be displayed when [[dataProvider]] does not have any data.
*/
public
$emptyText
;
/**
* @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:
...
...
@@ -83,6 +86,9 @@ abstract class BaseListView extends Widget
if
(
$this
->
dataProvider
===
null
)
{
throw
new
InvalidConfigException
(
'The "dataProvider" property must be set.'
);
}
if
(
$this
->
emptyText
===
null
)
{
$this
->
emptyText
=
Yii
::
t
(
'yii'
,
'No results found.'
);
}
$this
->
dataProvider
->
prepare
();
}
...
...
@@ -91,13 +97,13 @@ abstract class BaseListView extends Widget
*/
public
function
run
()
{
if
(
$this
->
dataProvider
->
getCount
()
>
0
||
$this
->
empty
===
false
)
{
if
(
$this
->
dataProvider
->
getCount
()
>
0
||
$this
->
showOnEmpty
)
{
$content
=
preg_replace_callback
(
"/
{
\\w+
}
/"
,
function
(
$matches
)
{
$content
=
$this
->
renderSection
(
$matches
[
0
]);
return
$content
===
false
?
$matches
[
0
]
:
$content
;
},
$this
->
layout
);
}
else
{
$content
=
'<div class="empty">'
.
(
$this
->
empty
===
null
?
Yii
::
t
(
'yii'
,
'No results found.'
)
:
$this
->
empty
)
.
'</div>'
;
$content
=
$this
->
renderEmpty
()
;
}
$tag
=
ArrayHelper
::
remove
(
$this
->
options
,
'tag'
,
'div'
);
echo
Html
::
tag
(
$tag
,
$content
,
$this
->
options
);
...
...
@@ -126,6 +132,16 @@ abstract class BaseListView extends Widget
}
/**
* Renders the HTML content indicating that the list view has no data.
* @return string the rendering result
* @see emptyText
*/
public
function
renderEmpty
()
{
return
'<div class="empty">'
.
(
$this
->
emptyText
===
null
?
Yii
::
t
(
'yii'
,
'No results found.'
)
:
$this
->
emptyText
)
.
'</div>'
;
}
/**
* Renders the summary text.
*/
public
function
renderSummary
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment