Sunday 27 April 2014

CButtonColumn in CGridView

CButtonColumn in CGridView:

          In previous post describes how to load data in the CGrideView and to perform CRUD functionality we need grid buttons for view, edit, delete.

Link for CGridView to load data from database.

then add the following lines inorder to get the buttons in gridview.

<?php

$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'student-grid',
    'dataProvider' => $model->getDisplayData(),
    //'filter' => $model,
    'selectableRows' => 2,
    'columns' => array(
        array(
            'header' => 'S.No',
            'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)'
        ),
        array(
            'name' => 'id',
            'header' => 'ID'
        ),
        array(
            'name' => 'name',
            'header' => 'Student Name'
        ),
        array(
            'name' => 'age',
            'header' => 'Age'
        ),
        array(
            'name' => 'mark1',
            'header' => 'Mark1'
        ),
        array(
            'name' => 'mark2',
            'header' => 'Mark2'
        ),
        array(
            'name' => 'mark3',
            'header' => 'Mark3'
        ),
        array('class' => 'CButtonColumn',
            'viewButtonUrl' => 'Yii::app()->controller->createUrl("site/view",array("id"=>$data["id"]))',
            'updateButtonUrl' => 'Yii::app()->controller->createUrl("site/sample",array("id"=>$data["id"]))',
            'deleteButtonUrl' => 'Yii::app()->controller->createUrl("site/delete",array("id"=>$data["id"]))',
        )
    ),
));
?>

Link for CButtonColumn Documentation

        Create actions for the View, edit, delete and map the actions in the craeteurl property of the CButtonColumn and send number of parameters with array.

Related Links:

CGridView display data from database in Yii PHP Framework

How to configure / install PHP Yii Framework on Netbeans


No comments:

Post a Comment