PHP code example of vandzaxe / yii2-sortable-gridview
1. Go to this page and download the library: Download vandzaxe/yii2-sortable-gridview library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vandzaxe / yii2-sortable-gridview example snippets
use vandzaxe\sortable\SortableAction;
public function actions(){
return [
'sortItem' => [
'class' => SortableAction::className(),
'activeRecordClassName' => YourActiveRecordClass::className(),
'orderColumn' => 'name_of_field_storing_ordering',
],
// your other actions
];
}
use vandzaxe\sortable\SortableGridView;
<?= SortableGridView::widget([
'dataProvider' => $dataProvider,
// you can choose how the URL look like,
// but it must match the one you put in the array of controller's action()
'sortUrl' => Url::to(['sortItem']),
// The starting number of the sort. Default sort starts at 0.
'startNumber' => 0,
// The incremental number of the sort. Default increment is 1.
'incrementalNumber' => 1,
'columns' => [
// Data Columns
],
]);
$dataProvider->pagination = false;
use vandzaxe\sortable\SortableAction;
public function actions(){
return [
'sortItem' => [
'class' => SortableAction::className(),
'activeRecordClassName' => Articles::className(),
'orderColumn' => 'sortOrder',
],
// your other actions
];
}