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
some screen shot
Please upload some screen shot please so we will know how it works..
Screenshot
There it goes :)
Very Helpful, but something is missing....
I think you are missing this instruction....., the field must not be named 'order' , but anything else....
second is ordering in CGridView,
add this to your model's search():
return new CActiveDataProvider(get_class($this), array( 'criteria' => $criteria, 'sort' => array( 'defaultOrder' => 'order_c asc', ), ) );
Here order_c is my table field..
also the image of arrows should be a little bit longer and a little bit separated , so i did is,
added this css to your extensions .css file,
.order_link img{ float: left; width: 20px; margin-left: 6px; -moz-border-radius :5px; border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border: 1px solid #d2d2d2; }
Thats it,
Again thanks for giving such a helpful extension.
Re: Very Helpful, but something is missing....
@tanimgt, yes this was one important instruction missing, thankyou!
As long as you reference the order field by the table name it is ok to name as order, its up to people how they name it anyway but inside the extension I've taken care of it by referencing order by the table name. And I would agree not to name order as the column name since its a reserved word inside SQL.
Again thanks for the helpful comment :)
@rookie84 good works ! very useful .
at recent i was do something with joomla , in its backend i found this reorder functionality . it 's wonderful , so i search from extension repo and come here . you could download joomla and have a look at it .
by the way , what about using the nestedset extension ? you may consider adding this to your todo list ,you see there are some ordering method : moveBefore/moveAfter....
Thanks
Glad you liked it :)
Nice extension
I've been looking for something like this for a long time, any idea how to use it with treetable extension? The idea is to create a relation between rows and subrows so the parent row should move together with its subrows.
Thank you.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.