yii2 sort with dropdown
<p>I have problem with sorting in listview yii2. I don't know how can I create dropdown list with sorting in Separate filter form.</p>

<p>In model I have:</p>

<pre><code>$dataProvider-&gt;sort-&gt;attributes['sort'] = [
            'asc' =&gt; ['game.rating' =&gt; SORT_ASC],
            'desc' =&gt; ['game.rating' =&gt; SORT_DESC],
        ];
</code></pre>

<p>but how create drop down?</p>

<p>Model:</p>

<pre><code>class GameSearch extends Offer
{

    public $status;
    public $title;
    public $type;
    public $platform;
    public $rating;
    public $pageSize;
    public $sort;


    public function rules()
    {
        return [
            [['status', 'platform', 'pageSize'], 'integer'],
            [['title', 'type', 'sort', 'rating'], 'string']
        ];
    }

    public function search($params, $query)
    {
        $query-&gt;joinWith(['game', 'author']);


        $dataProvider = new ActiveDataProvider([
            'query' =&gt; $query,
            'sort' =&gt; ['defaultOrder' =&gt; ['created_at' =&gt; SORT_DESC]],
            'pagination' =&gt; [
                'pageSize' =&gt; $this-&gt;pageSize,
            ],
        ]);

        $dataProvider-&gt;sort-&gt;attributes['sort'] = [
            'asc' =&gt; ['game.rating' =&gt; SORT_ASC],
            'desc' =&gt; ['game.rating' =&gt; SORT_DESC],
        ];

        if (!($this-&gt;load($params) &amp;&amp; $this-&gt;validate())) {
            return $dataProvider;
        }

        $dataProvider-&gt;pagination-&gt;pageSize = $this-&gt;pageSize;

        $query-&gt;andFilterWhere(['like', 'game.title', $this-&gt;title])
            -&gt;andFilterWhere(['like', 'platform', $this-&gt;platform]);

        return $dataProvider;
    }
}
</code></pre>

<p>and my search file</p>

<pre><code> &lt;?= $form-&gt;field($model, 'sort')
                -&gt;dropDownList([
                    'rating' =&gt; 'rating ASC',
                    '-rating' =&gt; 'rating DESC',
                ])
                -&gt;label(false)
                -&gt;error(false);
            ?&gt;
</code></pre>