HOW TO create grid table with CGridView widget?

Discuss everything related to ApPHP Durecty CMF. All versions. Any questions related to the Directy CMF developing or using should be posted to this forum.

Moderators: alexandrleonenko, alexmst

administrator
Site Admin
Site Admin
Posts: 6169
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO create grid table with CGridView widget?

Postby administrator » May 2nd, '13, 07:52

Working with gridView is a very simple process.
You have to define it in a following way (look in framework/helpers/widgets/CGridView.php for more info):

Code: Select all

echo CWidget::create('CGridView', array(
    'model'=>'Countries',
    'actionPath'=>'locations/view',
    'defaultOrder'=>array('priority_order'=>'DESC', 'name'=>'ASC'),
    'pagination'=>array('enable'=>true, 'pageSize'=>10),
    'sorting'=>true,
    'filters'=>array(),   /* filters section */
    'fields'=>array(),    /* fields definition section */
    'actions'=>array(),   /* action links definition section */
));


Here the full example for table Countries:

Code: Select all

<a href="locations/add" class="add-new">+ Add New</a>
<?php
    echo CWidget::create('CGridView', array(
        'model'=>'Countries',
        'actionPath'=>'locations/view',
        'defaultOrder'=>array('priority_order'=>'DESC', 'name'=>'ASC'),
        'pagination'=>array('enable'=>true, 'pageSize'=>10),
        'sorting'=>true,
        'filters'=>array(
            'name' => array('title'=>'Name', 'type'=>'textbox', 'operator'=>'like%', 'width'=>'140px', 'maxLength'=>''),
            'code' => array('title'=>'Code', 'type'=>'textbox', 'operator'=>'like%', 'width'=>'60px', 'maxLength'=>'2'),
        ),
        'fields'=>array(
            'name' => array('title'=>'Name', 'type'=>'label', 'class'=>'left'),
            'code'  => array('title'=>'Code', 'type'=>'label', 'class'=>'center', 'width'=>'110px'),
            'priority_order' => array('title'=>'Priority', 'type'=>'label', 'class'=>'center', 'width'=>'110px'),
            'is_default  => array('title'=>'Default', 'type'=>'enum', 'source'=>array('0'=>'No', '1'=>'Yes')),
            'is_active' => array('title'=>'Active', 'type'=>'enum', 'source'=>array('0'=>'No', '1'=>'Yes')),
        ),
        'actions'=>array(
            'edit'   => array('enable'=>true, 'link'=>'locations/edit/{id}', 'imagePath'=>'images/edit.png'),
            'delete' => array('enable'=>true, 'link'=>'locations/delete/{id}', 'imagePath'=>'images/delete.png'),
        ),
    ));
?>


The result may be viewed here:
grid.png
grid.png (31.66 KiB) Viewed 3952 times


P.S. To perform a numeric sort on some column - define for this field

Code: Select all

.., 'sortType' => 'numeric'

Return to “ApPHP Directy CMF {developers/users}”