PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 9, 2022

[FIXED] How to sort and filter with checkbox in yii

 January 09, 2022     cgridview, php, yii     No comments   

Issue

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.


Solution

The problem wos in config... adding line:

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

solves the problem.



Answered By - TomLi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing