joinWith('orderProducts') ->with('label.lang') ->select( [ 'order.*', 'count(*)', ] ) ->groupBy('order.id')->orderBy('created_at DESC'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider( [ 'query' => $query, 'sort' => [ 'attributes' => [ 'count', 'id', 'user_id', 'name', 'label_id', 'created_at', 'phone', 'email', ], ], ] ); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere( [ 'id' => $this->id, 'user_id' => $this->user_id, 'label_id' => $this->label_id, 'delivery_id' => $this->delivery_id, 'payment_id' => $this->payment_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at, 'count' => $this->count, ] ); $query->andFilterWhere( [ 'like', 'name', $this->name, ] ) ->andFilterWhere( [ 'like', 'phone', $this->phone, ] ) ->andFilterWhere( [ 'like', 'email', $this->email, ] ) ->andFilterWhere( [ 'like', 'city', $this->city, ] ) ->andFilterWhere( [ 'like', 'address', $this->address, ] ) ->andFilterWhere( [ 'like', 'comment', $this->comment, ] ); return $dataProvider; } }