Yii 2.0: yii2-sortable-widgets

Implementation the Rubaxa/Sortable for Yii2 widgets
3 followers

Yii2 Sortable widgets

Implementation Rubaxa/Sortable for Yii2 widgets.

Supported:

  • GridView widget.

demo

Usage ΒΆ

Create a new migration, change a parent to the migration class from the extension and specify the table name property:

class m140811_131705_Models_order extends \kotchuprik\sortable\migrations\Migration
{
    protected $tableName = 'models';
}

Add the sortable behavior to your model and specify the query property:

public function behaviors()
{
    return [
        'sortable' => [
            'class' => \kotchuprik\sortable\behaviors\Sortable::className(),
            'query' => self::find(),
        ],
    ];
}

Add the sorting action to your controller and specify the query property:

public function actions()
{
    return [
        'sorting' => [
            'class' => \kotchuprik\sortable\actions\Sorting::className(),
            'query' => \vendor\namespace\Model::find(),
        ],
    ];
}

Add the column to your grid view and specify the sorting url like here:

echo \yii\grid\GridView::widget([
    'dataProvider' => $model->search(),
    'columns' => [
        [
            'class' => \kotchuprik\sortable\grid\Column::className(),
        ],
        'id',
        'title',
        'order',
    ],
    'options' => [
        'data' => [
            'sortable-widget' => 1,
            'sortable-url' => \yii\helpers\Url::toRoute(['sorting']),
        ]
    ],
]);

Total 6 comments

#19539 report it
Constantin Chuprik at 2015/08/26 07:16am
thanks

ok, thank you for using :)

#19538 report it
Amjad Khan at 2015/08/26 07:12am
Working like a charm,thanks

Thank you very much, now it is working like a charm i ve just change "id" to "pkattributeid" in your column class because in my table i was using pkattributeid, and following code in actions in the controller

'query' => \common\models\Attribute::find(),

Thanks

#19537 report it
Constantin Chuprik at 2015/08/26 06:56am
response

it's your namespace. like:

backend\models\Model
#19536 report it
Amjad Khan at 2015/08/26 06:52am
namespace

Constantin Chuprik thanks for your reply, Sorry i cannot understand ,what is "my namespace, is it the namespace to my model or did you mean

'query' => \vendor\kotchuprik\sortable\actions\Model::find(),
#19535 report it
Constantin Chuprik at 2015/08/26 06:21am
updated Readme

Amjad Khan, thank you for reporting. I have updated Readme, please look it. Just add my namespace to Sorting class.

#19534 report it
Amjad Khan at 2015/08/26 06:13am
more explanation is required

i use this extension but got the following error

Class 'backend\controllers\Sorting' not found

-i added this extension manually using the following link
http://stackoverflow.com/questions/30480329/install-yii2-extension-manually-without-using-composer
-change the table on which i want to implement sorting in my database with a new column sortorder
-change the attribute name in the extension folder from "order" to sortorder but it is not working yet

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet