How to sort and filter with checkbox in yii

323 Views Asked by At

I have gridview with filters+checkboxes like below: filters+checkboxes

Gridview is filtered when checkbox is checked and its working v. nice but when i'm clicking on the column name to sort columns sort is taking controll over the filters and they just stop working...

I cant even unclick checkboxes and change values in filters inputs cause "sort" keeps values from before i clicked column name.

Is there any way to repair this?

My search function in model looks like below:

public function Search(): CActiveDataProvider
{
    $request = Yii::app()->request;
    $requestusr = $request->getParam('Users');

    $this->xyz_name_filter = isset($requestusr['xyz_name_filter']) ? $requestusr['xyz_name_filter'] : 1;
    $this->xyz_surname_filter = isset($requestusr['xyz_surname_filter']) ? $requestusr['xyz_surname_filter'] : 1;
    $this->xyz_street_filter = isset($requestusr['xyz_street_filter']) ? $requestusr['xyz_street_filter'] : 0;

    $criteria = new CDbCriteria();
    $this->xyz_name_filter == 1 ? $criteria->compare('t.xyz_name', $this->xyz_name, true) : null;
    $this->xyz_surname_filter == 1 ? $criteria->compare('t.xyz_surname', $this->xyz_surname, true) : null;
    $this->xyz_street_filter == 1 ? $criteria->compare('t.xyz_street', $this->xyz_street, true) : null;

    return new CActiveDataProvider(
        $this, array(
            'criteria' => $criteria,
            'pagination' => array(
                'pageSize' => $this->pagesize,
            ),
        )
    );
}

Thanks for reply.

2

There are 2 best solutions below

0
TomLi On BEST ANSWER

The problem wos in config... adding line:

'admin/<lang:[a-z]{2}>/<controller:\w+>/<action:\w+>'=>'admin/<lang>/<controller>/<action>'

solves the problem.

1
Aram Grigoryan On

Please debug the code what you see in the backed when clicking to sort with some value and add this to your code. For example, the request came as $requestusr['xyz_name_filter_ASC']

And add this in your code

 $this->xyz_name_filter_ASC == 1 ? $criteria->order = 't.xyz_name ASC';

In your code you have not any order