Yii Framework Forum: Search CGridView, related tables, dates and datepicker - Yii Framework Forum

Jump to content

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

Search CGridView, related tables, dates and datepicker Rate Topic: -----

#1 User is offline   artjc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 15-November 10
  • Location:Bogota

Posted 20 December 2010 - 11:34 AM

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.

4. 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
0

#2 User is offline   drumaddict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 04-October 10
  • Location:Athens,Greece

Posted 09 April 2011 - 03:36 AM

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


juidatepicker

0

#3 User is offline   ClaCS 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 21-January 11

  Posted 12 April 2011 - 12:20 PM

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

    ?>

1

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