auto-count-sql-data-provider

AutoCountSqlDataProvider has the ability to use pagination without first counting all the rows, thus increasing performance.
6 followers

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

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension