Yii Framework Forum: Pencarian Melalui Form - Yii Framework Forum

Jump to content

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

Pencarian Melalui Form Rate Topic: -----

#1 User is offline   mrkoeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 31-October 12
  • Location:Indonesia

Posted 28 April 2013 - 11:07 PM

permisi gan,
saya mau tanya. .
saya bikin pencarian data di cgridview, sperti ini penampakannya. .
Attached File  Capture.PNG (7.3K)
Number of downloads: 39

lha yg saya tanyakan, gmna cara buat ngirim variabel2 dari form diatas gan??
terimakasih. . .

#tanggal menggunakan datepicker, textfield milih dari cjuidialog. .
0

#2 User is offline   Nur Rochim 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 04-February 13
  • Location:Indonesia

Posted 29 April 2013 - 12:56 AM

ikut nyimak gan  ;D 

0

#3 User is offline   jimmi nababan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 12-October 09

Posted 03 May 2013 - 01:02 AM

mungkin lebih baik kalau disertakan dengan kode.

dan biasanya ini bermainnya diseputaran model.
ngirimnya pake ajax, form nya di form _search

coba lihat fungsi search yang ada di model, dan perhatikan kodenya.

View Postmrkoeh, on 28 April 2013 - 11:07 PM, said:

permisi gan,
saya mau tanya. .
saya bikin pencarian data di cgridview, sperti ini penampakannya. .
Attachment Capture.PNG

lha yg saya tanyakan, gmna cara buat ngirim variabel2 dari form diatas gan??
terimakasih. . .

#tanggal menggunakan datepicker, textfield milih dari cjuidialog. .

0

#4 User is offline   mrkoeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 31-October 12
  • Location:Indonesia

Posted 03 May 2013 - 04:12 AM

View Postjimmi nababan, on 03 May 2013 - 01:02 AM, said:

mungkin lebih baik kalau disertakan dengan kode.

dan biasanya ini bermainnya diseputaran model.
ngirimnya pake ajax, form nya di form _search

coba lihat fungsi search yang ada di model, dan perhatikan kodenya.


_search.php
<?php
/* @var $this PendapatanBaruController */
/* @var $model PendapatanBaru */
/* @var $form CActiveForm */
?>

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl($this->route),
	'method'=>'get',
)); ?>

	<table>
	<tr>
		<td><b>Periode</b></td>
		<td> : </td>
		<td>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'name'=>'tgl_awal',  // name of post parameter
				'value'=>isset(Yii::app()->request->cookies['tgl_awal']) ? Yii::app()->request->cookies['tgl_awal'] : '',
				 'options'=>array(
					'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
				),
				'htmlOptions'=>array(
					'style'=>'height:20px;'
				),
			));
			?>
		</td>
		<td><center><b> s/d </b></center></td>
		<td>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'name'=>'tgl_akhir',
				'value'=>isset(Yii::app()->request->cookies['tgl_akhir']) ? Yii::app()->request->cookies['tgl_akhir'] : '',
				 'options'=>array(
					'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
				),
				'htmlOptions'=>array(
					'style'=>'height:20px;'
				),
			));
			?>
		</td>
	</tr>
	<tr>
		<td><b>Dokter </b></td>
		<td> : </td>
		<td>
			<input type="hidden" name="id_text" id="id_text" />
			<input type="text" readonly="readonly" name="nama_text" id="nama_text" />  
		</td>
		<td>
			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#nama_text").val("");$("#id_text").val("")')) ?>
			<?php echo CHtml::Button('Get Dokter',  
					array('onclick' => '$("#dialogdokter").dialog("open"); return false;',  
				));  
			?>
		</td>
	</tr>
	<tr>
		<td><b>Unit Pelayanan </b></td>
		<td> : </td>
		<td>
			<input type="hidden" name="id_layanan" id="id_layanan" />
			<input type="text" readonly="readonly" name="nama_layanan" id="nama_layanan" />  
		</td>
		<td>
			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#nama_layanan").val("");$("#id_layanan").val("")')) ?>
			<?php echo CHtml::Button('Get Layanan',  
					array('onclick' => '$("#dialogpelayanan").dialog("open"); return false;',  
				));  
			?>
		</td>
	</tr>
</table>

	<div class="row buttons">
		<?php echo CHtml::submitButton('Search'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- search-form -->

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
	'id'=>'dialogdokter',
	'options'=>array(
		'title'=>'Daftar Dokter',
		'autoOpen'=>false,
		'modal'=>true,
		'width'=>550,
		'height'=>470,
	),
)); 
echo $this->renderPartial('loadDokter', array('model'=>$model));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
	'id'=>'dialogpelayanan',
	'options'=>array(
		'title'=>'Daftar Layanan',
		'autoOpen'=>false,
		'modal'=>true,
		'width'=>550,
		'height'=>470,
	),
)); 
echo $this->renderPartial('loadPelayanan', array('model'=>$model));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>


controller:
public function actionCariDetail()
	{
		$model=new ViewPendapatan('searchdetail');
		$model->unsetAttributes(); // clear any default values
		if(isset($_GET['ViewPendapatan']))
			$model->attributes=$_GET['ViewPendapatan'];
			$this->renderPartial('admin',array(
				'model'=>$model,
			),false,true);

		Yii::app()->end();
	}


model:
public function searchdetail($tgl_awal,$tgl_akhir,$kd_dokter,$kd_pelayanan)
	{
		$criteria=new CDbCriteria;
		$criteria->addBetweenCondition('tanggal',$tgl_awal,$tgl_akhir,'AND');
		$criteria->addCondition('id',$kd_dokter);
		$criteria->addSearchCondition('unit_pelaksanaa', $kd_pelayanan);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


ini gan sourcecodeny. . .
0

#5 User is offline   jimmi nababan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 12-October 09

Posted 05 May 2013 - 10:57 PM

kalau yang ditanya bagaimana mengirimnya, masukin aja fieldnya di form _search file itu,
link dengan modelnya, click search pasti langsung bisa, sama seperti yang advance mode form.

adakah error yang dihasilkan dari kode dibawah ini ?

cara tergampang, ubah file _search nya, lalu lihat perubahannya.



View Postmrkoeh, on 03 May 2013 - 04:12 AM, said:

_search.php
<?php
/* @var $this PendapatanBaruController */
/* @var $model PendapatanBaru */
/* @var $form CActiveForm */
?>

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl($this->route),
	'method'=>'get',
)); ?>

	<table>
	<tr>
		<td><b>Periode</b></td>
		<td> : </td>
		<td>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'name'=>'tgl_awal',  // name of post parameter
				'value'=>isset(Yii::app()->request->cookies['tgl_awal']) ? Yii::app()->request->cookies['tgl_awal'] : '',
				 'options'=>array(
					'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
				),
				'htmlOptions'=>array(
					'style'=>'height:20px;'
				),
			));
			?>
		</td>
		<td><center><b> s/d </b></center></td>
		<td>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'name'=>'tgl_akhir',
				'value'=>isset(Yii::app()->request->cookies['tgl_akhir']) ? Yii::app()->request->cookies['tgl_akhir'] : '',
				 'options'=>array(
					'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
				),
				'htmlOptions'=>array(
					'style'=>'height:20px;'
				),
			));
			?>
		</td>
	</tr>
	<tr>
		<td><b>Dokter </b></td>
		<td> : </td>
		<td>
			<input type="hidden" name="id_text" id="id_text" />
			<input type="text" readonly="readonly" name="nama_text" id="nama_text" />  
		</td>
		<td>
			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#nama_text").val("");$("#id_text").val("")')) ?>
			<?php echo CHtml::Button('Get Dokter',  
					array('onclick' => '$("#dialogdokter").dialog("open"); return false;',  
				));  
			?>
		</td>
	</tr>
	<tr>
		<td><b>Unit Pelayanan </b></td>
		<td> : </td>
		<td>
			<input type="hidden" name="id_layanan" id="id_layanan" />
			<input type="text" readonly="readonly" name="nama_layanan" id="nama_layanan" />  
		</td>
		<td>
			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#nama_layanan").val("");$("#id_layanan").val("")')) ?>
			<?php echo CHtml::Button('Get Layanan',  
					array('onclick' => '$("#dialogpelayanan").dialog("open"); return false;',  
				));  
			?>
		</td>
	</tr>
</table>

	<div class="row buttons">
		<?php echo CHtml::submitButton('Search'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- search-form -->

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
	'id'=>'dialogdokter',
	'options'=>array(
		'title'=>'Daftar Dokter',
		'autoOpen'=>false,
		'modal'=>true,
		'width'=>550,
		'height'=>470,
	),
)); 
echo $this->renderPartial('loadDokter', array('model'=>$model));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
	'id'=>'dialogpelayanan',
	'options'=>array(
		'title'=>'Daftar Layanan',
		'autoOpen'=>false,
		'modal'=>true,
		'width'=>550,
		'height'=>470,
	),
)); 
echo $this->renderPartial('loadPelayanan', array('model'=>$model));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>


controller:
public function actionCariDetail()
	{
		$model=new ViewPendapatan('searchdetail');
		$model->unsetAttributes(); // clear any default values
		if(isset($_GET['ViewPendapatan']))
			$model->attributes=$_GET['ViewPendapatan'];
			$this->renderPartial('admin',array(
				'model'=>$model,
			),false,true);

		Yii::app()->end();
	}


model:
public function searchdetail($tgl_awal,$tgl_akhir,$kd_dokter,$kd_pelayanan)
	{
		$criteria=new CDbCriteria;
		$criteria->addBetweenCondition('tanggal',$tgl_awal,$tgl_akhir,'AND');
		$criteria->addCondition('id',$kd_dokter);
		$criteria->addSearchCondition('unit_pelaksanaa', $kd_pelayanan);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


ini gan sourcecodeny. . .

0

#6 User is offline   mrkoeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 31-October 12
  • Location:Indonesia

Posted 06 May 2013 - 01:27 AM

View Postjimmi nababan, on 05 May 2013 - 10:57 PM, said:

kalau yang ditanya bagaimana mengirimnya, masukin aja fieldnya di form _search file itu,
link dengan modelnya, click search pasti langsung bisa, sama seperti yang advance mode form.

adakah error yang dihasilkan dari kode dibawah ini ?

cara tergampang, ubah file _search nya, lalu lihat perubahannya.



iya gan, udah solved. .
kmren saya gak kepkiran, trus ternyata ad file yang salah panggil jadi gak bisa menghasilkan ap2. .

terimkasih atas fast responnya. .

ini di _search :
<?php
/* @var $this PendapatanBaruController */
/* @var $model PendapatanBaru */
/* @var $form CActiveForm */
?>

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl($this->route),
	'method'=>'get',
)); ?>

	<table>
	<tr>
		<td><b>Periode</b></td>
		<td> : </td>
		<td>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'name'=>'ViewPendapatan[tgl_awal]',  // name of post parameter
				//'value'=>isset(Yii::app()->request->cookies['ViewPendapatan[tgl_awal]']) ? Yii::app()->request->cookies['ViewPendapatan[tgl_awal]'] : '',
				  'value' => $model->tgl_awal,
				 'options'=>array(
					'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
					'changeMonth'=> 'true',
					'changeYear'=> 'true',
				),
				'htmlOptions'=>array(
					'style'=>'height:20px;'
				),
			));
			?>
		</td>
		<td><center><b> s/d </b></center></td>
		<td>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'name'=>'ViewPendapatan[tgl_akhir]',
				//'value'=>isset(Yii::app()->request->cookies['ViewPendapatan[tgl_akhir]']) ? Yii::app()->request->cookies['ViewPendapatan[tgl_akhir]'] : '',
				 'value' => $model->tgl_akhir,
				 'options'=>array(
					'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
					'changeMonth'=> 'true',
					'changeYear'=> 'true',
				),
				'htmlOptions'=>array(
					'style'=>'height:20px;'
				),
			));
			?>
		</td>
	</tr>
	<tr>
		<td><b>Dokter </b></td>
		<td> : </td>
		<td>
			<?php echo $form->hiddenField($model,'id'); ?>
			<?php echo $form->textField($model,'nama'); ?>
		</td>
		<td>
			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#ViewPendapatan_nama").val("");$("#ViewPendapatan_id").val("")')) ?>
			<?php echo CHtml::Button('Get Dokter',  
					array('onclick' => '$("#dialogdokter").dialog("open"); return false;',  
				));  
			?>
		</td>
	</tr>
	<tr>
		<td><b>Unit Pelayanan </b></td>
		<td> : </td>
		<td>
			<?php echo $form->hiddenField($model,'id'); ?>
			<?php echo $form->textField($model,'unit_pelaksanaa'); ?>
		</td>
		<td>
			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#ViewPendapatan_unit_pelaksanaa").val("");$("#ViewPendapatan_id").val("")')) ?>
			<?php echo CHtml::Button('Get Layanan',  
					array('onclick' => '$("#dialogpelayanan").dialog("open"); return false;',  
				));  
			?>
		</td>
	</tr>
</table>

	<div class="row buttons">
		<?php echo CHtml::submitButton('Search'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- search-form -->

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
	'id'=>'dialogdokter',
	'options'=>array(
		'title'=>'Daftar Dokter',
		'autoOpen'=>false,
		'modal'=>true,
		'width'=>550,
		'height'=>470,
	),
)); 
echo $this->renderPartial('loadDokter', array('model'=>$model));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
	'id'=>'dialogpelayanan',
	'options'=>array(
		'title'=>'Daftar Layanan',
		'autoOpen'=>false,
		'modal'=>true,
		'width'=>550,
		'height'=>470,
	),
)); 
echo $this->renderPartial('loadPelayanan', array('model'=>$model));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>


ini di model:
public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		
		if((isset($this->tgl_awal) && trim($this->tgl_awal) != "") && (isset($this->tgl_akhir) && trim($this->tgl_akhir) != ""))
			$criteria->addBetweenCondition('tanggal', ''.$this->tgl_awal.'', ''.$this->tgl_akhir.'');

		$criteria->compare('kode_param',$this->kode_param);
		$criteria->compare('tanggal',$this->tanggal,true);
		$criteria->compare('id',$this->id);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('unit_pelaksanaa',$this->unit_pelaksanaa,true);
		$criteria->compare('nama_ruangan',$this->nama_ruangan,true);
		$criteria->compare('jml_pend_lay',$this->jml_pend_lay);
		$criteria->compare('jml_jasa',$this->jml_jasa); 
			
		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}

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