hello,
help me pliz, i’m a new guy in Yii framework, i’m tring to make multiple selection checkbox in GridView and i’m using yii booster too.
here is my code.
controller code :
public function actionIndex()
{
$sqlquery="select id,nama,panggilan,alamat1,kota,jabatan,status from karyawan";
$datakaryawan=Karyawan::model()->findAllBySql($sqlquery);
$jadiarray = new CArrayDataProvider($datakaryawan,array('pagination'=>array('pageSize'=>5)));
$isigrid=$this->bentukkolom();
$formkaryawan=new Karyawan;
$this->render('index',array('datakaryawan'=>$jadiarray,'isigrid'=>$isigrid,'formkaryawan'=>$formkaryawan));
}
private function bentukkolom()
{
$isigrid= array(
array('class'=>'CCheckBoxColumn','selectableRows' => 2,'checkBoxHtmlOptions' => array( 'name' => 'userids[]'),),
array('name'=>'id', 'header'=>'No.','htmlOptions'=>array('style'=>'width: 40px')),
array('name'=>'nama', 'header'=>'Nama Lengkap'),
array('name'=>'panggilan', 'header'=>'Panggilan'),
array('name'=>'alamat1', 'header'=>'Alamat 1'),
array('name'=>'kota', 'header'=>'Kota'),
array('name'=>'jabatan', 'header'=>'Jabatan'),
array('name'=>'status', 'header'=>'Status'),
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'booster.widgets.TbButtonColumn',
'viewButtonUrl'=>null,
'updateButtonUrl'=>null,
'deleteButtonUrl'=>'Yii::app()->createUrl("karyawan/hapus", array("id"=>$data->id))',
)
);
return $isigrid;
}
public function actionHapusglobal()
{
//if(Yii::app()->request->isAjaxRequest){
//if(isset($_POST['ids'])) {
echo "get in herey";
//print_r( $_POST['']);
foreach($_POST['theIds'] as $val) {
echo $val . '<br/>';
}
// }
//}
}
}
and my view
<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<div class="row">
<div class="col-lg-12" style="padding-top:20px ">
<h2 style="padding-left:200px ">MASTER DATA KARYAWAN DAN USER</h2>
<?php $box = $this->beginWidget('booster.widgets.TbPanel',
array(
'title' => 'DAFTAR KARYAWAN',
'headerIcon' => 'user',
'padContent' => false,
'htmlOptions' => array('class' => 'bootstrap-widget-table'),
'headerButtons' =>
array(
array(
'class' => 'booster.widgets.TbButtonGroup',
'context' => 'primary',
//'toggle' => 'radio',
'buttons' =>
array(
array('label' => 'Left', 'url' => '#'),
array('label' => 'Hapus Global', 'url' => '#',
//'onclick' => 'js:hapusbulk()',
//'id'=>'delete',
),
/*array('label' => 'Tambah', 'url' => '#',
'htmlOptions' => array(
'data-toggle' => 'modal',
'data-target' => '#formModal',),
//'onclick' => "js: submitForm()",
),*/
),
),
),
)
);
?>
<div id="for-link">
<?PHP
$this->widget(
'booster.widgets.TbGridView',
array(
'id'=>'gridcust',
'type' => 'striped hover',
'dataProvider' => $datakaryawan,
'template' => "{items}{pager}",
'columns' => $isigrid,
'enablePagination' => true,
'enableSorting'=>true,
)
);
?>
<?php $this->endWidget(); ?>
<?php $this->renderPartial('_form',array('model'=>$formkaryawan));?>
<div id="output">asd</div>
</div>
</div>
<?php
Yii::app()->clientScript->registerScript('delete','
$("#yw2").click(function(){
var checked=$("#gridcust").yiiGridView("getChecked","gridcust_c0"); // _c0 means the checkboxes are located in the first column, change if you put the checkboxes somewhere else
var count=checked.length;
if(count==0){
alert("No items selected");
}
if(count>0 && confirm("Do you want to delete these "+count+" item(s)"))
{
$.ajax({
data:{checked:checked},
url:"'.CHtml::normalizeUrl(array('karyawan/hapusglobal')).'",
success:function(data){$("#gridcust").yiiGridView("update",{});},
});
}
});
');?>
result of checked grid alwas return no items selected, even i’ve checked all grid. i’ ve tried these links
link 1
and link 2
but the result alwasys return zero, whats wrong with my code, help me plis?