Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to limit query for ActiveDataProvider? [duplicate]

I am trying to make a query to get the first 10 records for example, and pass it to the ActiveDataProvider.

The query is working fine and returning the required number of records only, while the ActiveDataProvider is printing all the records, here is my code:

    $query = new \yii\db\Query;
    $query->select('*')
            ->from('customers')
            ->limit(10);
    $query->createCommand();

    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);
like image 821
Mohammad Avatar asked Mar 13 '23 21:03

Mohammad


1 Answers

Set Pagination to false :

$dataProvider = new ActiveDataProvider([
'pagination' => false
]);

Reference

like image 175
Insane Skull Avatar answered Mar 17 '23 08:03

Insane Skull