ordercolumn Adds an order column to the CGridView and lets you reorder through up and down links/icons

  1. Requirements
  2. Installation
  3. Usage

OrderColumn is a simple extension that extends CGridColumn and lets you add up and down arrows for reordering the Grid. Easy to use!

Requirements

Yii 1.0 or above PHP 5.* You should have an order field/column and you yourself do the job of incrementing it each time you insert a record.

Installation

  • Extract under protected/extensions/OrderColumn
  • Follow usage instructions.

Usage

Assuming you have a field in model/table called order instructions for having up and down arrows in the Order Column are as follows:

(1) Put this inside the controller:

public function actions()
        {
            return array(
              'order' => array(
                  'class' => 'ext.OrderColumn.OrderAction',
                  'modelClass' => 'Post',
                  'pkName'  => 'id',
                  ),
            );
        }

‘modelClass’ refers to the model in the above example it refers to the Post model I have.

(2) Inside the view where you have the CGridView widget add a column for the ordering icons:

array(
                  'header' => 'Order',
                  'name' => 'order',
                  'class' => 'ext.OrderColumn.OrderColumn',
                ),

‘name’ => ‘order’ refers to the field in the table/model it can be anything as you have defined.

(3) Add this to your model's search():

return new CActiveDataProvider(get_class($this), array(
            'criteria' => $criteria,
             'sort' => array(
                'defaultOrder' => 't.order asc',
            ),
                )
        );

Where order is again the db field and can be anything as you've defined.

(4) That’s it, it you should be able to do the reordering through the up/down icons

13 0
16 followers
738 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: rookie84
Created on: Feb 24, 2012
Last updated: 12 years ago

Downloads

show all

Related Extensions