Created
April 10, 2013 12:00
-
-
Save udibagas/5354007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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