Reputation: 411
im using Pjax gridview,After I search the results,when I click pagination ,the results changed to default results page not search result. and my search function is like
public function search($params)
{
$query = UserLogs::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,'pagination'=> ['defaultPageSize' => PAGE_SIZE],
'sort' => [
'defaultOrder' => [
'user_log_id' => SORT_DESC,
]
],
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->joinWith('user');
// grid filtering conditions
$query->andFilterWhere([
'user_log_id' => $this->user_log_id,
//'user_id' => $this->user_id,
'user_logs.user_type_id' => $this->user_type_id,
'login_time' => $this->login_time,
'logout_time' => $this->logout_time,
]);
$query->andFilterWhere(['like', 'login_ip', $this->login_ip])
->andFilterWhere(['like', 'juser.firstname', $this->user_id]);
return $dataProvider;
}
Edit#1: my grid view file is :
<?php Pjax::begin(['clientOptions' => ['method' => 'POST']]);?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
.....
['class' => 'yii\grid\ActionColumn','template' => '{view}'],
],
]); ?>
<?php Pjax::end();?>
Upvotes: 3
Views: 2562
Reputation: 1
I have solved this problem by "self join".
In your model file write this code for self join.
public function getUserLogs()
{
return $this->hasOne(UserLogs::className(), ['user_id' => 'user_id', 'user_log_id' => 'user_log_id']);
}
In your search function write this code
public function search($params)
{
$query = UserLogs::find();
$query->joinWith('user_logs as u_l');
$dataProvider = new ActiveDataProvider([
'query' => $query,'pagination'=> ['defaultPageSize' => PAGE_SIZE],
'sort' => [
'defaultOrder' => [
'user_log_id' => SORT_DESC,
]
],
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->joinWith('user');
// grid filtering conditions
$query->andFilterWhere([
'u_l.user_log_id' => $this->user_log_id,
'u_l.user_id' => $this->user_id,
'u_l.user_type_id' => $this->user_type_id,
'u_l.login_time' => $this->login_time,
'u_l.logout_time' => $this->logout_time,
]);
$query->andFilterWhere(['like', 'u_l.login_ip', $this->login_ip])
->andFilterWhere(['like', 'user.firstname', $this->user_id]);
return $dataProvider;
}
Upvotes: 0
Reputation: 133
Change your POST to GET, this should make the pagination work along with any of your other filters.
Upvotes: 4