Drag and Drop Sorting in Yii CGridView: the server-side logic

K. Kakousis

I have recently used a nice Yii extension that builds ontop of JQuery UI Sortable and CGridView to implement the drag & drop sorting effect on my table’s rows.

The only thing left to figure out was a way to maintain my records ordered after each order change. Here is a simple approach that worked for me:

First of all we will need a table column for storing the order, let’s name it sort_order.

avoid using ‘order’ as a table column since it is a MySQL reserved keyword!

From the client side we already have the ids of the rows dragged and replaced. So on the php action called upon ajax call we could do something like this:

*although there is some Yii-specific code here the logic can be applied regardless of the framework or language.

View original post


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s