Creating a jQueryUI Sortable CGridView

Comparing #1 with #2

Revision #2 was created by blindMoe blindMoe on Sep 19, 2011, 8:49:14 PM.

Adjusted Step #2 to be Optional

Content

I have had to do this a couple of times now so I figured I would share it with the community. I am going to keep this short because I really hope that you are familiar with [jQueryUI's Sortable](http://jqueryui.com/demos/sortable/ "jQueryUI's Sortable") class before starting this tutorial. Here are the basic steps to achieve this: 1. Make sure your database table has a 'sortOrder' field. 2. (Optional) Add the 'sortOrder' field to your Rules() function in your model
3. Add the 'sort()' function to your controller to apply the sorting via ajax
4. Add jQuery UI to your view that has the CGridView
[...]
**Step 2:** This step is optional but recommended.  Add this line to the model who's items you are sorting.  Without this line your item's sortOrder will never be saved:

```php
array('sortOrder', 'numerical', 'integerOnly'=>true),
```
[...]