Yii Framework Forum: Unable To Search Date In Cgridview - Yii Framework Forum

Jump to content

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

Unable To Search Date In Cgridview Rate Topic: -----

#1 User is offline   rangganovsky 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 15-October 12

Posted 06 October 2013 - 10:42 AM

Hi Everyone,

All i want to do is just able to filter using date on gridview / advanced search section. i have search for the answer and tried several method but unfortunately, the problem is still persist to me. i'm even not using between range of date scenario. the objective is simple so the user should be able to search on spesific date, and all data on that date should be displayed on the gridview.

here is the date widget on my search form :
<div class="row">
		<?php echo $form->label($model,'tgl_surat_jalan'); ?>
		
		 <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
        'model'=>$model,
        'attribute'=>'tgl_surat_jalan',
		'value' => $model->tgl_surat_jalan, 		
        // additional javascript options for the date picker plugin
        'options'=>array(
            'showAnim'=>'fold',
            'dateFormat'=>'yy-mm-dd',
        ),
        'htmlOptions'=>array(
            //'style'=>'height:10px;',
            'value'=>date('Y-m-d'),
        ),
        )); ?>
	</div>


and here is the search criteria on my model (as i point my dataProvider to $model->dibuat()) :
public function dibuat()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('kode',$this->kode,true);
		$criteria->compare('mobil',$this->mobil,true);
		$criteria->compare('no_rangka',$this->no_rangka,true);
		$criteria->compare('no_mesin',$this->no_mesin,true);
		$criteria->compare('warna_id',$this->warna_id,true);
		$criteria->compare('dealer_id',$this->dealer_id,true);
		$criteria->compare('asal',$this->asal,true);
		$criteria->compare('tujuan',$this->tujuan);
		$criteria->compare('ongkos',$this->ongkos,true);
		$criteria->compare('harga',$this->harga,true);
		$criteria->compare('keterangan',$this->keterangan,true);
		//$criteria->compare('tgl_surat_jalan',$this->tgl_surat_jalan,true);
		$criteria->compare('tgl_surat_jalan',CDateTimeParser::parse($this->tgl_surat_jalan, 'yyyy-MM-DD'),true);
		$criteria->compare('status','Dibuat',true,'AND');
      
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


i'm able filter with the other attribute, but if i tried to filter using datefield then the search function is not working. am i missing something here? i'm just curious how search method work for datefield in yii.

Regards,

Razril
0

#2 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,269
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 06 October 2013 - 11:07 AM

Try to adjust the pattern for CDateTimeParser.parse(). It's still at the default in your case which absolutely doesn't match the format you specified for the date picker.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#3 User is offline   rangganovsky 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 15-October 12

Posted 06 October 2013 - 10:32 PM

thanks for the reply, i've tried to change the datefortmat on my model :
CDateTimeParser::parse($this->tgl_surat_jalan, 'yy-mm-dd')

to match the dateformat on the datepicker as you suggest but no success. i'm still unable to filter datefield.
am i missing something? the date format should be year-month-date as its the same with the date format on database.
0

#4 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,269
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 07 October 2013 - 02:40 AM

Oh, so the field in the database is of the VARCHAR type? CDateTimeParser.parse() will produce an integer representing a unix timestamp. I think you do not need to use it at all. Just set a validation rule in place for the search scenario.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#5 User is offline   rangganovsky 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 15-October 12

Posted 07 October 2013 - 10:14 PM

actually, the field in the database is DATE type with (Y-m-d) format i.e: 2013-01-20.
i see, so CDateTimeParser.parse() will produce integer unix stamp format. so is there any other way to format the datefield after the user clicked search button? in case the dateformat returned by the datepicker is incorrect.
and i also already added the tgl_surat_jalan in rule() on search. but still no success.

and sorry for another silly question, i also have tried to var_dump the $criteria on models, to find out what value $this->tgl_surat_jalan has. but var_dump($criteria) seems it always returning default value with all the fields null. even though i search using multiple conditions. like id and tgl_surat_jalan.
so, where should i put the var_dump to find out what value exactly $this->tgl_surat_jalan has?

Thanks,
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