Yii Framework Forum: Select2 Return - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Select2 Return Rate Topic: -----

#1 User is offline   AndroideLP 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 18-June 13

Posted 06 December 2013 - 08:32 AM

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
Posted Image
0

#2 User is offline   AndroideLP 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 18-June 13

Posted 06 December 2013 - 09:44 AM

View PostAndroideLP, on 06 December 2013 - 08:32 AM, said:

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
Posted Image



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 }; }',
        ),
       ),
         
        ));

0

#3 User is offline   keiny 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 22-April 14

Posted 19 May 2014 - 07:40 AM

My value does not save, shows error 404
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users