Skip to content

Instantly share code, notes, and snippets.

@udibagas
Created April 10, 2013 12:00
Show Gist options
  • Save udibagas/5354007 to your computer and use it in GitHub Desktop.
Save udibagas/5354007 to your computer and use it in GitHub Desktop.
<?php
/* Di view */
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'my-grid', // perhatikan ini
...
'columns' => array(
...
array(
'name' => 'status',
'value' => '$data->status
? "<input type=\"checkbox\" checked=\"checked\" value=\"{$data->id}\" onClick=\"changeStatus(this.value)\" />"
: "<input type=\"checkbox\" value=\"{$data->id}\" onClick=\"changeStatus(this.value);\" />"',
'htmlOptions' => array('style' => 'text-align:center;vertical-align:middle;'),
'filter' => array('0' => 'N', '1' => 'Y'),
'type' => 'raw', // harus seperti ini!!!
),
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
)
)
)); ?>
<script type="text/javascript">
var changeStatus = function(id) {
$.ajax({
type: 'post',
url: '<?php echo Yii::app()->createUrl('my/changeStatus'); ?>/'+id, // sesuaikan url-nya
success: function(r) {
$.fn.yiiGridView.update('my-grid'); // sesuaikan dengan id grid-nya
}
});
}
</script>
<?php
/* Di contollernya */
class MyController extends Controller {
//...
public function actionChangeStatus($id) {
$model = $this->loadModel($id);
$model->status = $model->status == 1 ? 0 : 1; // toggle
$model->save();
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment