Yii Framework Forum

Select2 Return


(And4563) #1

Good morning,

I’m trying to work with select2 using ajax because my database query has more than 5,000 lines.

But the result of the ajax. it does not filter the query, bringing the entire query on the screen.

controler


 public function actionFiltroCargo(){

                   $lista =CargoEspecifico::model()->findAll(array('limit'=>50)); 

                   $reusultados = array();

                   foreach ($lista as $list){

           $reusultados[] = array(

                        'id'=>$list->id,

                        'text'=>  $list->Nome,

           ); 

        }

                echo CJSON::encode($reusultados);   

                    

                }

form




        echo "<h2>Cargo especifico</h2>";

        

        echo CHtml::hiddenField('CargoespecSearch', '', array('class' => 'span5'));

        $this->widget('ext.select2.ESelect2',array(

            'selector' => '#CargoespecSearch',

            'options'  => array(

            

            'allowClear'=>true,

           'placeholder'=>'Selecione o Cargo Específico',

           'minimumInputLength' => 4, 

           'ajax' => array(

            'url' => Yii::app()->createUrl('curriculo/filtrocargo'),

            'dataType' => 'json',

            'quietMillis'=> 100,

            'data' => 'js: function(text,page) {

                    return {

                        q: text, 

                        page_limit: 10,

                        page: page,

                    };

                }',

            'results'=>'js:function(data,page) { var more = (page * 10) < data.total; return {results: data, more:more }; }',

        ),

       ),

         

        ));

Printscreen error


(And4563) #2

I managed to solve.

The problem is that I did not pass the parameters via get

controller:


 public function actionFiltroCargo(){

                    

                   

                    

                   $lista =CargoEspecifico::model()->findAll('Nome like :Nome',array(':Nome'=>"%".$_GET['q']."%")); 

                   $reusultados = array();

                   foreach ($lista as $list){

           $reusultados[] = array(

                        'id'=>$list->id,

                        'text'=>  $list->Nome,

           ); 

        }

                echo CJSON::encode($reusultados);   

                    

                }

form:


 echo CHtml::hiddenField('CargoespecSearch', '', array('class' => 'span5'));

        $this->widget('ext.select2.ESelect2',array(

            'selector' => '#CargoespecSearch',

            'options'  => array(

            'allowClear'=>true,

           'placeholder'=>'Selecione o Cargo Específico',

           'minimumInputLength' => 4, 

           'ajax' => array(

            'url' => Yii::app()->createUrl('curriculo/filtrocargo'),

             'type'=>'GET',

            'dataType' => 'json',

            'quietMillis'=> 100,

            'data' => 'js: function(text,page) {

            return {

                        //get im my controller

                        q: text, 

                        page_limit: 10,

                        page: page,

                    };

                }',

            'results'=>'js:function(data,page) { var more = (page * 10) < data.total; return {results: data, more:more }; }',

        ),

       ),

         

        ));


(Ktpacheco1) #3

My value does not save, shows error 404