Thursday, 3 January 2013

Yii CGridView with CCheckBoxColumn with ajaxbutton


<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'orders-products-grid',
    'dataProvider' => $model->search(),
    'columns' => array(
        array(
            'header' => 'Item #',
            'value' => '++$row',
        ),
        'products_name',
        'products_quantity',
        array(
            'header' => 'Price',
            'value' => '"$".number_format($data->final_price*$data->products_quantity,2)',
        ),
        array(
            'header' => 'Confirmed?',
            'value' => '$data->bought == 0? "No" : "Yes"',
        ),
        array(
            'class' => 'CCheckBoxColumn',
            'selectableRows' => 2,
            'checked' => '$data->bought==1',
            'id' => 'boughtCheck'
        )
    ),
));
?>

<?php
echo CHtml::ajaxButton('Confirm', yii::app()->createUrl('site/checkBought'), array(
    'type' => 'POST',
    'data' => 'js:{value : $.fn.yiiGridView.getChecked("orders-products-grid","boughtCheck")}',
    'success'=>'js:function(data){
                 $.fn.yiiGridView.update("orders-products-grid");
    }'
));

No comments:

Post a Comment