Yii Framework Forum

Search CGridView, related tables, dates and datepicker


(Alephart) #1

Hi everyone,

I have several questions, all interrelated:

  1. By placing the datepicker in a CGridView in the first search no problem but after this, the datepicker does not work anymore.

  2. Besides this my datepicker change the language after the first search and is in Chinese and not the language I want. I imagine that if I put as default language in javascript would be the solution, but I do not know how.

  3. Search CGridView between two dates

I want to locate a datapicker in a column in a CgridView to search through a range of two dates, but not how to cover this issue. I was not as easy to operate the CDbCriteria for this case. I need a light please.

  1. I also wish to search in related tables, I do not know how to properly use CDbCriteria and CActiveDataProvider to relate multiple tables.

I appreciate your help to have any idea how to start this.

JC

Sorry for my English


(Kabasakalis) #2

For your no1 problem which I also had this extension is a solution

[color=#222222][font=Arial, sans-serif][size=2]

juidatepicker

[/size][/font][/color]


(Cscs2410) #3

Hi!

This is a small code that I did a while ago. I hope this helps guide you to what you want




<?php


$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);

             

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

	'id'=>'lectivo-grid',

	'dataProvider'=>$model->search(),

        'cssFile'=> bUrl().'/css/gridview/gridview.css',

        'filter'=>$model,

        'pager' => array(

                'nextPageLabel' => 'Siguiente',

                'prevPageLabel' => 'Anterior',

                'firstPageLabel' => 'Primero',

                'lastPageLabel' => 'Último',

                'header' => '',

                'maxButtonCount' => 5,

                'cssFile' => bUrl().'/css/pagination/pagination.css'

        ),

	    'columns'=>array(

        

        array(

            'class'=>'CCheckBoxColumn',

        ),

		

        array(

                        'name' => 'id_lectivo',

                        'header' => 'ID',

                        'filter'=>false,

                        'htmlOptions'=>array('align'=>'center')

        ),

        

		'nombre',

		'abreviatura',

		

        array(

                        'name' => 'fec_inicio',

                        'value' => 'UtilFechas::aFechaNormal($data->fec_inicio)',

                        'htmlOptions'=>array('align'=>'center','style'=>'width: 103px;'),

                        'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array(

                            'model'=>$model,

                            'attribute'=>'fec_inicio',

                            'language'=>'es',

                            'htmlOptions'=>array('style'=>'width: 80px;'),

                            'options' => array(

                                'dateFormat' => 'yy-mm-dd',

                                'changeYear' => true,

                                'showOn' => 'button',

                                'buttonImage' => bUrl() . '/images/icons/calendar.png',

                                'buttonImageOnly' => true

                            )

                        ), true),

        ),

		

        array(

                        'name' => 'fec_fin',

                        'value' => 'UtilFechas::aFechaNormal($data->fec_fin)',

                        'htmlOptions'=>array('align'=>'center','style'=>'width: 103px;'),

                        'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array(

                            'model'=>$model,

                            'attribute'=>'fec_fin',

                            'language'=>'es',

                            'htmlOptions'=>array('style'=>'width: 80px;'),

                            'options' => array(

                                'dateFormat' => 'yy-mm-dd',

                                'changeYear' => true,

                                'showOn' => 'button',

                                'buttonImage' => bUrl() . '/images/icons/calendar.png',

                                'buttonImageOnly' => true

                            )

                        ), true),

        ),

		

        array(

                        'name' => 'estado',

                        'value' => '$data->estado',

                        'htmlOptions'=>array('align'=>'center'),

                        'filter'=>array('1'=>1,'0'=>0),

        ),


        array(

                'class'=>'CButtonColumn',

                'header'=>CHtml::dropDownList('pageSize',

                    $pageSize,

                    array(10=>10,20=>20,50=>50),

                    array('onchange'=>"$.fn.yiiGridView.update('lectivo-grid',{ data:{pageSize: $(this).val() }})",)

                    ),

        ),

	),

    'afterAjaxUpdate'=>'function(){

    	jQuery("#'.CHtml::activeId($model, 'fec_inicio').'").datepicker({

                    dateFormat: \'yy-mm-dd\',

                    changeYear: true,

                    showOn: \'button\',

                    buttonImage:\''.bUrl().'/images/icons/calendar.png\',

                    buttonImageOnly: true

               });$.datepicker.setDefaults($.datepicker.regional["es"]);

		jQuery("#'.CHtml::activeId($model, 'fec_fin').'").datepicker({

                    dateFormat: \'yy-mm-dd\',

                    changeYear: true,

                    showOn: \'button\',

                    buttonImage:\''.bUrl().'/images/icons/calendar.png\',

                    buttonImageOnly: true

               });$.datepicker.setDefaults($.datepicker.regional["es"]);

		    }',

));


    ?>