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
647aa71a
Commit
647aa71a
authored
Sep 26, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #909 from bixuehujin/dataprovider
Fixed pagination not working before data loaded
parents
220db270
b7948e48
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
2 deletions
+18
-2
ActiveDataProvider.php
framework/yii/data/ActiveDataProvider.php
+0
-1
ArrayDataProvider.php
framework/yii/data/ArrayDataProvider.php
+0
-1
DataProvider.php
framework/yii/data/DataProvider.php
+1
-0
ActiveDataProviderTest.php
tests/unit/framework/data/ActiveDataProviderTest.php
+17
-0
No files found.
framework/yii/data/ActiveDataProvider.php
View file @
647aa71a
...
...
@@ -156,7 +156,6 @@ class ActiveDataProvider extends DataProvider
throw
new
InvalidConfigException
(
'The "query" property must be an instance of Query or its subclass.'
);
}
if
((
$pagination
=
$this
->
getPagination
())
!==
false
)
{
$pagination
->
totalCount
=
$this
->
getTotalCount
();
$this
->
query
->
limit
(
$pagination
->
getLimit
())
->
offset
(
$pagination
->
getOffset
());
}
if
((
$sort
=
$this
->
getSort
())
!==
false
)
{
...
...
framework/yii/data/ArrayDataProvider.php
View file @
647aa71a
...
...
@@ -114,7 +114,6 @@ class ArrayDataProvider extends DataProvider
}
if
((
$pagination
=
$this
->
getPagination
())
!==
false
)
{
$pagination
->
totalCount
=
$this
->
getTotalCount
();
$models
=
array_slice
(
$models
,
$pagination
->
getOffset
(),
$pagination
->
getLimit
());
}
...
...
framework/yii/data/DataProvider.php
View file @
647aa71a
...
...
@@ -48,6 +48,7 @@ abstract class DataProvider extends Component implements DataProviderInterface
if
(
$this
->
id
!==
null
)
{
$this
->
_pagination
->
pageVar
=
$this
->
id
.
'-page'
;
}
$this
->
_pagination
->
totalCount
=
$this
->
getTotalCount
();
}
return
$this
->
_pagination
;
}
...
...
tests/unit/framework/data/ActiveDataProviderTest.php
View file @
647aa71a
...
...
@@ -85,4 +85,21 @@ class ActiveDataProviderTest extends DatabaseTestCase
$provider
->
refresh
();
$this
->
assertEquals
(
2
,
count
(
$provider
->
getModels
()));
}
public
function
testPaginationBeforeModels
()
{
$query
=
new
Query
;
$provider
=
new
ActiveDataProvider
(
array
(
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'tbl_order'
)
->
orderBy
(
'id'
),
));
$pagination
=
$provider
->
getPagination
();
$this
->
assertEquals
(
1
,
$pagination
->
getPageCount
());
$this
->
assertCount
(
3
,
$provider
->
getModels
());
$provider
->
getPagination
()
->
pageSize
=
2
;
$this
->
assertEquals
(
3
,
count
(
$provider
->
getModels
()));
$provider
->
refresh
();
$this
->
assertEquals
(
2
,
count
(
$provider
->
getModels
()));
}
}
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