AutoCountSqlDataProvider extends the CSqlDataProvider. It adds the ability to use pagination without first counting all the rows, thus increasing the performance when browsing large tables.
Requirements ¶
None
Usage ¶
# table_name has 15 rows.
$provider = new AutoCountSqlDataProvider(
'table_name',
new CDbCriteria(array('condition'=>'column1 is not null')),
false,
array(
'sort'=>array(
'attributes'=>array('column1','column2'),
),
'pagination'=>array(
'pageSize'=>10,
),
)
);
$rows = $provider->fetchData();
# count($rows) == 10
# $provider->hasMore == true
# $provider->getTotalItemCount() == 10
$rows = $provider->fetchData();
# count($rows) == 5
# $provider->hasMore == false
# $provider->getTotalItemCount() == 15
Where is the SQLDataProvider feature?
I'm sorry if I'm wrong, but as docs say:
"CSqlDataProvider implements a data provider based on a plain SQL statement."
The first parameter of this extension asks for a "table" name not SQL statement.
:(
Where is the SQLDataProvider feature?
The SQL statement is created by calling CDbCommandBuilder.createFindCommand and using the $table and $criteria parameters inside the constructor. The reason for this approach is that is easy and portable to generate also the count SQL query by calling CDbCommandBuilder.createCountCommand and using the same parameters. If you find that this approach is restrictive you might consider altering the behavior as needed. Can you also send me a patch of your changes and I will happily integrate them here.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.