Yii Framework Forum: Sort In Grid View - Yii Framework Forum

Jump to content

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

Sort In Grid View Rate Topic: -----

#1 User is offline   Aadhira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 06-February 13

Posted 06 February 2013 - 04:49 AM

hi all,is there any way to sort the content displayed in grid view?if so kindly help me.


Thanks in advance :)
<?php

$duplicateData = Yii::app()->db->createCommand()
->select('*')
->from('mail')
->queryAll();
$dataProvider = new CArrayDataProvider($duplicateData, array(
'pagination' => array(
'pageSize' => 10,
),
));


$this->widget('zii.widgets.grid.CGridView', array(

'dataProvider' => $dataProvider->search(),

array(
'name' => 'E_Id',
'header' => 'Email Id'
),
array(
'name' => 'Receiver',
'header' => 'Receiver'
),
)
));


?>
0

#2 User is offline   gv0zd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 06-April 12

Posted 06 February 2013 - 05:38 AM

In my code I use this
    public function search()
    {
        $criteria=new CDbCriteria;

        $criteria->compare('t.id',$this->id);
        $criteria->compare('typeId',$this->typeId);
        $criteria->compare('countryId',$this->countryId);
        $criteria->compare('t.title',$this->title,true);
        $criteria->compare('content',$this->content,true);
        $criteria->compare('created',$this->created,true);
        $criteria->compare('deleted',$this->deleted,true);

        $criteria->with=array('type', 'country');

        return new CActiveDataProvider(
            $this,
            array(
                'criteria'=>$criteria,
                'sort'=>array(
                    'defaultOrder'=>'type.id ASC, country.title ASC, t.title ASC',
                    'attributes'=>array(
                        'type.title'=>array(
                            'asc'=>$expr='type.title',
                            'desc'=>$expr.' DESC',
                        ),
                        'country.title'=>array(
                            'asc'=>$expr='country.title',
                            'desc'=>$expr.' DESC',
                        ),
                        '*'
                    )
                ),
                'pagination'=>array(
                    'pageSize'=>Yii::app()->params['pagination']['backoffice'],
                ),
            )
        );
    }

0

#3 User is offline   Aadhira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 06-February 13

Posted 07 February 2013 - 03:52 AM

View Postgv0zd, on 06 February 2013 - 05:38 AM, said:

In my code I use this
    public function search()
    {
        $criteria=new CDbCriteria;

        $criteria->compare('t.id',$this->id);
        $criteria->compare('typeId',$this->typeId);
        $criteria->compare('countryId',$this->countryId);
        $criteria->compare('t.title',$this->title,true);
        $criteria->compare('content',$this->content,true);
        $criteria->compare('created',$this->created,true);
        $criteria->compare('deleted',$this->deleted,true);

        $criteria->with=array('type', 'country');

        return new CActiveDataProvider(
            $this,
            array(
                'criteria'=>$criteria,
                'sort'=>array(
                    'defaultOrder'=>'type.id ASC, country.title ASC, t.title ASC',
                    'attributes'=>array(
                        'type.title'=>array(
                            'asc'=>$expr='type.title',
                            'desc'=>$expr.' DESC',
                        ),
                        'country.title'=>array(
                            'asc'=>$expr='country.title',
                            'desc'=>$expr.' DESC',
                        ),
                        '*'
                    )
                ),
                'pagination'=>array(
                    'pageSize'=>Yii::app()->params['pagination']['backoffice'],
                ),
            )
        );
    }





i dono for what $criteria->with=array('type', 'country'); is used .kindly explain it
0

#4 User is offline   fouss 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 385
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 07 February 2013 - 04:41 AM

the relational query criteria. This is used for fetching related objects in eager loading fashion

http://www.yiiframew...ria#with-detail
Posted Image
0

#5 User is offline   Aadhira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 06-February 13

Posted 07 February 2013 - 05:08 AM

View Postfouss, on 07 February 2013 - 04:41 AM, said:

the relational query criteria. This is used for fetching related objects in eager loading fashion

http://www.yiiframew...ria#with-detail

had seen it already ,but no clear idea about it
0

#6 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 315
  • Joined: 08-June 10
  • Location:France

Posted 08 February 2013 - 03:21 AM

Hi
Have a look at my extension RelatedSearchBehavior which makes sorting on related tables really easy to do.
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