Cgridview Filter Doesn't Seem To Work.

Hello guys,

I’m pretty new to Yii and I’ve been playing around with boilerplate and a downloaded theme and it went smooth until I stumbled upon this issue with the filters in the cgridview. For some reason it doesn’t return the filtered results. I’ve been trying to pinpoint the problem for a while and I noticed that the snippet that executes javascript


does not seem like it’s executing the javascript code but it does show it when you check the source code in Chrome.

When I try to filter the gridview it doesn’t show anything and this also happens if I make a new generated CRUD for another model in Gii, I can’t seem to fish out the problem out of this one. I’ve been struggling with this for hours.

Here’s the piece of code I’m fighting with. If more is necessary I’ll be more than happy to provide it.

My view

            Yii::app()->clientScript->registerScript('search', "




                        return false;


                $('.search-form form').submit(function(){

                        $('#companies-grid').yiiGridView('update', {

                                data: $(this).serialize()


                        return false;





            <div class="box box-solid">

                <div class="box-body">


            <div class="center-content">


            You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

            or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.


            <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

            <div class="search-form" style="display:none">

            <?php $this->renderPartial('_search',array(


            )); ?>


            </div><!-- search-form -->

            <?php $this->widget('zii.widgets.grid.CGridView', array(




                    'itemsCssClass'=>"table table-bordered table-hover dataTable",


                            'cid' => array('header' => '#', 'name'=>'cid', 'filterHtmlOptions'=> array('style' => 'width: 65px;')),

                            'name' => array('header' => 'Bedrijfsnaam', 'name'=>'name'),

                            'first_name' => array('header' => 'Voornaam', 'name'=>'first_name'),

                            'last_name' => array('header' => 'Achternaam', 'name'=>'last_name'),

                            'date_registration' => array('header' => 'Registratie datum', 'name'=>'date_registration', 'filter' => "<input type='text' name='Companies[date_registration]' id='datemask' data-inputmask='alias': 'dd/mm/yyyy' data-mask placeholder='dd/mm/yyyy'"),/*, filterHtmlOptions'=> array('id' => 'datemask', 'data-inputmask' => "'alias': 'dd/mm/yyyy'", 'data-mask'=>"")),*/

                            /*                            'kvk_number',


















            )); ?>


Search action

$model=new Companies('search');

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






Search in model

public function search()


		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;




		$criteria->compare('last_name',$this->last_name, true);
















		return new CActiveDataProvider($this, array(




I’m thinking it’s something with the javascript because this code does make sense for me, but hey ho I may be wrong… Would appreciate it if you guys know the solution and thanks in advance!

Got it solved thanks to someone clever in the live chat, the problem was 'em in the main layout where I loaded in jQuery myself when Yii already loads in jQuery from the core and that interfered with the core’s jQuery causing the cGridview and the advanced search to not work.

When you type anything in the grid filter fields and press enter it doesn’t filter the grid? I mean not in the advanced search form.

Please make sure you have added the safe rule in rules() method of the model.

    public function rules()


        return array(

            array('LIST OF COLUMNS HERE', 'safe', 'on' => 'search'),



Edit. I can see you solved it already. Glad everything is clear now.