<?php
$this->widget('zii.widgets.CMenu', array(
    'items' => array(
        array('label' => 'Управление комплектами тюнинга',
            'url' => Yii::app()->controller->createUrl("", array("crudAction" => "admin") + $_GET),
            'icon' => 'icon-resize-vertical', 'active' => false),

        array('label' => 'Добавить комплект тюнинга',
            'url' => Yii::app()->controller->createUrl("", array("crudAction" => "create") + $_GET),
            'icon' => 'icon-plus', 'active' => false),
    ),
    'htmlOptions' => array(
        'class' => 'nav nav-pills',
    ),
));
?>

    <h1>Список</h1>
    <br/>
<?php
echo CHtml::beginForm();

$groups = CHtml::listData($dataProvider->getData(), 'id', 'i18n.name', 'tuning_model_id');
echo '<div id="orderList">';
foreach ($groups as $tuning_model_id => $items) {
    if (count($items)) {
        $tuningModel = TuningModel::model()->findByPk($tuning_model_id);
        echo '<h2>', $tuningModel->i18n->name, '</h2>';

        $this->widget('zii.widgets.jui.CJuiSortable',
            array(
                'options' => array(
                    'stop' => 'js:function(event, ui) {
                         var vals = [];
                         $("#orderList .user-list").each(function(){
                            var val = $(this).sortable("toArray").join(",");
                            console.log(val);
                            vals.push(val);
                         });
                         $("#orderInput").attr("value",vals.join(","));
                    }',
                ),
                'items' => $items,
                'htmlOptions' => array(
                    'class' => 'user-list'
                ),
            ));
    }
}
echo '</div>';

echo CHtml::hiddenField('Order', 'none', array('id' => 'orderInput'));

echo CHtml::submitButton('Сохранить порядок', array('class' => 'btn btn-primary'));
echo Chtml::endForm();
?>