Answer the question
In order to leave comments, you need to log in
(Yii2) How to sort on click in ListView?
There are filters, I figured them out, but I need to change sorting by click, say by id.
So far I only understood how to set default
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => ['id' => SORT_DESC],
],
]);
Answer the question
In order to leave comments, you need to log in
Are there no examples? As far as I remember, when I last generated the code with the crud generator, fields were created where all sorts worked. And there was an example of a blog.
Have a look at Yii2's search model, or the easiest way is to go to Gii with cGrud. I'm right there in the rules model and sorted even arbitrary columns.
$searchModel = new ContentSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question