0

I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.

but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?

In my Controller

    $dataProvider=new CActiveDataProvider('Store', 
                    array(
                        'criteria' => array(
                            'condition'=>$_search_conditions, 
                            'params'=>$search_params,
                        ),
                        'sort'=>array(
                               'defaultOrder'=>'store DESC',
                                'attributes'=>array(
                                    'store'=>array(
                                        'asc'=>'store',
                                        'desc'=>'store DESC',
                                    ),
                                  '*',
                                )
                        ),
                    )
                );

$model = new Store;
$model->unsetAttributes();  // clear any default values

        //render page
        $this->render('index',array(
                'dataProvider'=>$dataProvider,
                'model'=>$model
        ));

In my View

$this->widget('zii.widgets.CListView', array(
                        'id' => 'store-list',
                        'dataProvider'=>$dataProvider,
                        'itemView'=>'_view',
                        'enableHistory'=> true,
                        'pagerCssClass' => 'pagination',
                        'ajaxUpdate'=>'store-list',
                        'loadingCssClass' => '', //remove loading icon
                        'sortableAttributes'=>array(
                            'store',
                            //'state' => 'State',
                            //'distance' => 'Distance'
                        ),
                        'emptyText' => '<div class="alert alert-info">No data found</div>',
                        'template'=>'
                                    <div class="row">
                                        <div class="col-md-12">     
                                            <div class="pull-left visible-lg visible-md visible-sm">{summary}</div>                     
                                            <div class="pull-right">{sorter}</div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">{items}</div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            {pager}
                                        </div>
                                    </div>',
                        'pager' => array('id'=>'_pagination',
                                         'class' => 'LinkPager',
                                         'header' => '', //remove pagination header
                                         'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
                                        ),
                    ));

also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class

if (!empty($_GET['sort']))
{
    echo $_GET['Store_sort'] = $_GET['sort'];
}

UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either

http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list
user2636556
  • 1,855
  • 4
  • 27
  • 58
  • Can you please tell me the url of the ajax request? – Dinistro Oct 22 '14 at 05:47
  • Is this still in your code: `echo $_GET['Store_sort'] = $_GET['sort'];`?, because with this you're overwriting the `Store_sort`-GET parameter – Dinistro Oct 22 '14 at 05:58
  • 1
    @Dinistro nope, disabled friendly url for now – user2636556 Oct 22 '14 at 06:00
  • Are you sure that the get parameter `Store_sort` is available in the action when you call it with ajax? You can try to print them out with `var_dump`. To look at the ajax request: http://stackoverflow.com/questions/1820927/request-monitoring-in-chrome – Dinistro Oct 22 '14 at 06:08
  • you mean i have to `$_GET['Store_sort']` in my `actionIndex()`? – user2636556 Oct 22 '14 at 06:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63458/discussion-between-dinistro-and-user2636556). – Dinistro Oct 22 '14 at 06:17

0 Answers0