Sorting Yii2 Gridview in descending order first
<p>I have a table rendered by Yii2 GridView. The table header contains the link to sort by date. If I click on it, it sorts the table first in ascending order and on the second click in descending order. But I want descending order on the first click.</p>

<p>I solved it with a hack in the search method of the search controller (asc->SORT_DESC):</p>

<pre><code>   $dataProvider-&gt;sort-&gt;attributes['updated_at'] = [ 
      'asc'  =&gt; [$this-&gt;tablename() . '.updated_at' =&gt; SORT_DESC ], 
      'desc' =&gt; [$this-&gt;tablename() . '.updated_at' =&gt; SORT_ASC], 
   ]; 
</code></pre>

<p>Is there a better solution?</p>