Yii Framework Forum: CGridView + pagination + sorting problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView + pagination + sorting problem Widget fails to display correct data. Rate Topic: -----

#1 User is offline   dimitri 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 14-August 12
  • Location:Estonia, Tallinn

Posted 14 August 2012 - 07:05 AM

How to reproduce:
  • Suppose we have a database table such as:
    CREATE TABLE [dbo].[tbl_device](
    	[id] [smallint] IDENTITY(1,1) NOT NULL,
    	[name] [varchar](50) NOT NULL,
    	[active] [bit] NULL
    );
    


  • Table contains ~300 entries, where column [active] can have only 1 or 0 ([bit] data type).
  • Using the Gii Code Generator, we generate a model class.
  • Now, using this model and CGridView widget with sorting capability, print out the contents of the table on the page.
  • Sort by 'Active' column.
  • Then list 5-10 pages using the 'Next>' button of the 'pager'.


Problem:
On some point we will see, that although page number is changed, the data in the grid is the same as it was on the previous page.
Moreover, this set of data (10 items by default) appears on several pages.

Configuration:
  • Yii 1.1.11
  • MS SQL Server 2012 Express
  • IIS 7
  • Windows 7


Will appreciate any help and suggestions.
0

#2 User is offline   alirz23 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 14 August 2012 - 07:31 AM

could be duplicate entries use distinct
0

#3 User is offline   dimitri 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 14-August 12
  • Location:Estonia, Tallinn

Posted 16 August 2012 - 01:44 AM

View Postalirz23, on 14 August 2012 - 07:31 AM, said:

could be duplicate entries use distinct


What did you mean?

If we are talking about full entry (SELECT * FROM...),
there are unique 'id's, thus there can not be duplicate entries.

And if we are talking about one column 'active' (SELECT active FROM...),
of course there are duplicate values. There are only 1s and 0s for 300 entries.

Probably, I misunderstood something?
0

#4 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,097
  • Joined: 05-January 12
  • Location:Morocco

Posted 16 August 2012 - 05:38 AM

Hello.

If the 1.11-experienced members don't know more about this, why don't you post an SQL export of your table so that we can test your case?

Cheers :)
0

#5 User is offline   CeBe 

  • Standard Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 180
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 16 August 2012 - 05:55 AM

Please post your code, maybe there is something wrong with it, are you using custom criteria in your dataprovider?
0

#6 User is offline   dimitri 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 14-August 12
  • Location:Estonia, Tallinn

Posted 16 August 2012 - 06:35 AM

Hello. :)

Technically, I am using almost 'default' code (with a few small changes) generated by Gii. These changes should not affect CGridView workflow.
So this is the part of code from 'admin.php' I used to configure and display CGridView:
<?php
$dataProvider = $model->search();
$dataProvider->pagination = array('pageSize' => 25);
$dataProvider->sort = array('defaultOrder' => 'name ASC');
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'device-grid',
    'dataProvider' => $dataProvider,
    'filter' => $model,
    'template' => "{summary}\n{pager}<br>\n{items}\n{pager}",
    'columns' => array(
        array(
            'header' => '#',
            'value' => '$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1',
        ),
        'name',
        'active',
        array(
            'class' => 'CButtonColumn',
            
        ),
));
?>


Where:
  • $model - is an ActiveRecord generated with Gii.
  • First column is a workaround to get the correct index number.


I can export my table also, but as I figured out, described strange behavior appears with all tables, where CGridView trying to sort data by a column containing a lot of identical entries.

Please, try it yourself.
If the problem appears, then it is a bug. If not, then it is a bug in my head. :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users