Yii2 Sortable widgets ¶
Implementation Rubaxa/Sortable for Yii2 widgets.
Supported:
- GridView widget.
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']),
]
],
]);
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
updated Readme
Amjad Khan, thank you for reporting. I have updated Readme, please look it. Just add my namespace to Sorting class.
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(),
response
it's your namespace. like:
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
thanks
ok, thank you for using :)
Hello,Why is it necessary to create a migration,and what is the path standard of query in the controller?
Why did the page return to the original order after the page refreshed, feeling that the transaction did not seem to be submitted successfully.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.