Yii Framework Forum: Hold Row At The Top Of Gridview - Yii Framework Forum

Jump to content

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

Hold Row At The Top Of Gridview Rate Topic: -----

#1 User is offline   justwasp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-September 12

Posted 31 July 2013 - 04:31 AM

Hello!

Please help me, if anyone can. How to form dataprovider so that one of the row for output to gridview has always been at the top?

I have a list of items that I want to display in the table and one of those items is the default value, that is, when user add a new item to the table, info from default item will be copied to the initial values ​​of new item.
I would like to see this defult item displayed in the table always at top in any sorting.
To indicate the default item has a separate field in the table, named 'default_user'.

I try this code:

$dataProvider = new CActiveDataProvider($this, array(
                            'criteria'=>$criteria,
                            'sort'=>array(
                                'multiSort'=>true,
                                'attributes'=>array(
                                    'username' => array(
                                        'asc' => 'default_user = 1, username ASC',
                                        'desc' => 'default_user = 1, username DESC'
                                    ),
                                    'useremail' => array(
                                        'asc' => 'default_user = 1, useremail ASC',
                                        'desc' => 'default_user = 1, useremail DESC'
                                    ),
                                ),                            
                                'defaultOrder'=>array(
                                    'username'=>CSort::SORT_ASC,
                                    'default_user'=> 1,
                                ),
                            )
                        ));


But when I change sorting by name to DESC - defult user go to the bottom of gridview.

What I do wrong?

Thanks for any help :)
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,707
  • Joined: 04-March 10
  • Location:UK

Posted 31 July 2013 - 07:34 AM

I feel like you should be sorting the default_user calculation in descending order each time:

                                'attributes'=>array(
                                    'username' => array(
                                        'asc' => 'default_user = 1 DESC, username ASC',
                                        'desc' => 'default_user = 1 DESC, username DESC'
                                    ),
                                    'useremail' => array(
                                        'asc' => 'default_user = 1 DESC, useremail ASC',
                                        'desc' => 'default_user = 1 DESC, useremail DESC'
                                    ),
                                ),                            

0

#3 User is offline   justwasp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-September 12

Posted 31 July 2013 - 09:25 AM

Sorry but nothing happen. It still move to down
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