kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

Pagination does not work properly with SqlDataProvider #151

Closed stesifrancesco closed 7 years ago

stesifrancesco commented 7 years ago

I'm tring to use dynagrid with sql data provider. All seems to wirk properly except pagination, for example if I try to show 5 items for page I got this:

Showing 1-5 of 0 elements (I have 18 elements in my data provider)

Here is my data-provider:

` $dataProvider = new SqlDataProvider([
            'sql' =>  $query->createCommand()->getRawSql(),
            'totalCount' => $itemsCount,
            'key' => 'id',
//'pagination' => false, // I tried several configuration for pagination without result
            'sort'=> ['attributes'=>[
                "id",
                "code",
                "name",
                "vat_id",
                "active",
                "customer",
                "supplier",
                "created_at",
                "created_by",
                "parameters"
            ]]
        ]);

            return $dataProvider;

One more information: if I use the same DataProvider with simple Grid (without dynagrid I got correctly Showing 1-5 of 18 elements)

Any idea ?

Thanks in advance for your supports (and many thanks to kartik fro it's wonderful extensions)

Francesco

kartik-v commented 7 years ago

You must configure totalCount property of the SqlDataProvider to the total record count value. This is required for SqlDataProvider as highlighted in Yii Docs and you should be able to see that in Dynagrid output (confirmed as tested by me separately).

kartik-v commented 7 years ago

However I am noting an enhancement for data providers other than active data providers.

stesifrancesco commented 7 years ago

Hi Kartik and thanks for your answer. You mean in this way: $itemsCount = $query->count(); ? Because I alredy tried in this way without success

kartik-v commented 7 years ago

Set dataProvider['totalCount'] = 40 for example and try. That should show total count showing up as 40.

Once you tested that - then you need to check how you calculate the total count from your query.

stesifrancesco commented 7 years ago

dataProvider for what I know is an object, so I alredy tried to set: $dataProvider->setTotalCount(40); either

 $dataProvider = new SqlDataProvider([
            'sql' =>  $query->createCommand()->getRawSql(),
            'totalCount' => 40,
            'key' => 'id',
            'pagination' => [
                'pageSize' => 7
            ],
            'sort'=> ['attributes'=>[
                "id",
                "code",
                "name",
                "vat_id",
                "active",
                "customer",
                "supplier",
                "created_at",
                "created_by",
                "parameters"
            ]]
        ]);

Without success....(showin 1-10 of 0 elements)

As I wrote this issue is only with dynagrid. With your grid and with the same data provider all work without problems.

kartik-v commented 7 years ago

This is resolved via this mega commit for updates to release v1.4.5.

stesifrancesco commented 7 years ago

Now It works fine: Thanks a lot !