PHP code example of yetopen / yii2-models-sorting
1. Go to this page and download the library: Download yetopen/yii2-models-sorting 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/ */
yetopen / yii2-models-sorting example snippets
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
// Sort column
[
'class' => \MP\ARSorting\ARSortColumn::class,
'attribute' => 'sort',
'hideColumn' => false,
],
[
'attribute' => 'created_at',
'format' => ['date', 'format' => 'php: d/m/Y H:i:s'],
],
['class' => 'yii\grid\ActionColumn'],
],
]);
class SampleController extends Controller
{
...
public function actions(): array
{
return array_merge(parent::actions(), [
'mp-ar-sort' => \MP\ARSorting\ARSortAction::class,
]);
}
...
}
class SampleModel extends ActiveRecord
{
...
/**
* @inheritdoc
*/
public function behaviors(): array
{
return [
[
'class' => \MP\ARSorting\ARSortBehavior::class,
'attribute' => 'sort',
// Optional
'queryCondition' => function ($query, self $model) {
$query->andWhere(['parent_id' => $model->parent_id]);
},
],
];
}
...
}