Problem With Sorting Cgv With Relations After Filtering

hi guys,

I was digging forum and wiki to find a solution for sorting and filtering relational and other columns. I found some like Dynamic parent and child CGridView on single view. Using $.ajax to update child gridview via controller, after row in parent gridview was clicked. and CGridView Filtering related tables and some others. finally filtering and sorting are working but not in a friendly way. if I filter one column then sorting crashes!

I have no idea about this, can anyone help me?

Model:




class User extends CActiveRecord

{

    public $parent_search;

    public $group_search;

public function rules()

	{

array('group_search, parent_search, id,..., status', 'safe', 'on'=>'search'),

}

public function search()

	{

		$criteria=new CDbCriteria;


        $criteria->with = array('parentCode', 'group');

        $criteria->together =true;

        

        $criteria->compare('parentCode.username', $this->parent_search, true);

        

        $criteria->compare('group.name', $this->group_search, true);


		$criteria->compare('t.id',$this->id);

		$criteria->compare('t.firstName',$this->firstName,true);

		$criteria->compare('t.lastName',$this->lastName,true);

		$criteria->compare('t.username',$this->username,true);

		$criteria->compare('t.password',$this->password,true);

		$criteria->compare('t.email',$this->email,true);

		$criteria->compare('t.birthday',$this->birthday,true);

		$criteria->compare('t.countryId',$this->countryId,true);

		$criteria->compare('t.address',$this->address,true);

		$criteria->compare('t.postalCode',$this->postalCode,true);

		$criteria->compare('t.parentCode',$this->parentCode);

		$criteria->compare('t.status',$this->status,true);


        $sort = new CSort;

        $sort->attributes = array(

            'parent_search'=>array(

                'asc'=>'parentCode.username',

                'desc'=>'parentCode.username DESC',

            ),

            'group_search'=>array(

                'asc'=>'name',

                'desc'=>'name DESC',

            ),

            '*',

        );

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

            'sort'=>$sort,

		));



Controller:




public function actionTest()

	{

        $model = new User('search');

        

        $model->unsetAttributes();

        

        if(isset($_GET['User']))

        {

            $model->attributes = $_GET['User'];

        }        

        $this->render('indexTest', array('model'=>$model));

	}



View:




<h1>Manage Users</h1>


<div id="statusMsg" style="display:none;"></div>




<?php $this->widget('CGridView', array(

	'id'=>'user-grid',

    'enableSorting'=>TRUE,

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

    'filter'=>$model,

	'columns'=>array(

    	array(

    			'name'=>'id',

    			'htmlOptions'=>array('style'=>'width: 4%;'),

                'filter'=>  CHtml::activeTextField($model, 'id', array('style'=>'width: 50%;')),

    	),

        array(

            'name'=>'firstName',

            'htmlOptions'=>array('style'=>'width: 14.5%;'),

            'filter'=>  CHtml::activeTextField($model, 'firstName', array('style'=>'width: 60%;')),

        ),

        array(

            'name'=>'lastName',

            'htmlOptions'=>array('style'=>'width: 14.5%;'),

            'filter'=>  CHtml::activeTextField($model, 'lastName', array('style'=>'width: 60%;')),

        ),

        array(

            'name'=>'username',

            'htmlOptions'=>array('style'=>'width: 14.5%;'),

            'filter'=>  CHtml::activeTextField($model, 'username', array('style'=>'width: 60%;')),

        ),

		array(

				'header'=>'Group Name',

				'name'=>'group_search',

                'value'=>'($data->group) ? $data->group->name : ""',

                'htmlOptions'=>array('style'=>'width: 14.5%;'),

                'filter'=>  CHtml::activeTextField($model, 'group_search', array('style'=>'width: 60%;')),

		),

        array(

            'header'=>'Parent',

            'name'=>'parent_search',

            'value'=>'($data->parentCode) ? $data->parentCode->username : ""',

            'htmlOptions'=>array('style'=>'width: 14.5%;'),

            'filter'=>  CHtml::activeTextField($model, 'parent_search', array('style'=>'width: 60%;')),

        ),

        array(

            'name'=>'creationDate',

            'htmlOptions'=>array('style'=>'width: 14.5%;'),

            'filter'=>  CHtml::activeTextField($model, 'creationDate', array('style'=>'width: 60%;')),

        ),        

		array(

			'class'=>'CButtonColumn',

				'buttons'=>array

				(

						'view' => array

						(

								'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/view.png',

						),

						'update' => array

						(

								'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/update.png',

						),

						'delete' => array

						(

								'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/delete.png',

						),

				),

				'afterDelete'=>'function(link,success,data){

					if(success && data) {

						var data = jQuery.parseJSON(data);

						$("#statusMsg").html(data.message).css("display","block").removeClass().addClass("flash flash-"+data.type).animate({opacity: 1.0}, 6000).fadeOut("slow");

					}

				}',

		),

			


	),


)); ?>



I have tried relatedsearchbehavior ext, but it doesn’t work too!

anybody to help on this?:(

Hi

If you check out this example for relatedsearchbehavior you can observe that filtering and ordering works.

So there is likely something in your setup which has to be done differently.

Check out the query that is created in order to see what is going on. It could be a matter of aliases being the same or other kinds of problems.