Fastest way to position items in CGridView


I’m not looking for a ready solution, as I can develop all the necessary code myself. I just wanted to ask, to see, if someone got some idea or experience on that, before I start again to re-develop the wheel.

So… What would be the easiest or fastest way to give user an ability to position items in CGridView in the order he or she wants?

Would that be introducing new column position (hidden in CGridView and not directly editable) and using two new buttons (move up / move down) to CButtonColumn - that would change value of that new column for current and surrounding items? Or maybe something better.

Thanks and cheers,


I use the same way, but sometimes I add ajax updating of grid when position was changed.

Thanks! I introduced solution I described in the beginning. For this particular project I don’t need AJAX updates, but the idea you provided sounds interesting.

I have a crummy way of doing it with my many_many tables.

Every time I update the many-many relationship (the children) I delete them and reinsert them all.

For a single table of items I think you’d have to use a position attribute.

If this is something the user will use once or twice, you cold provide a JuiDialog that allows a user to use jQuery’s sort.

I would bind to the stop event and fire an AJAX request to update the column_order property. This saves the user from seeing the Move Up & Move Down column during a regular browsing session.


jQuery’s sort was the first thing I thought about here. I have some (most strange) reason for avoiding it in this particular project:

  1. I don’t want to introduce jQuery UI, because project is already overloaded with libraries, and I don’t use jQuery UI at all. Introducing additional ~200k of JS code just to have one sort control isn’t the wisest idea in my opinion.

  2. Due to cost project is hosted on a very bad server*. AJAX works… from time to time. I know that this is idiotic assumption to use bad server for lower hosting costs, but this was customer’s decision, not mine.



  • very bad server = Can you imagine that someone actually is able to sell hosting services, offering PHP not updated for five years? I was shocked, if not terrified, when I found out that my piece of code is not working because PHP on that server is so old, that it hasn’t even got DateTime class!