I’m having three issues with Kartik gridview:
- Default sort doesn’t work.
‘default’ => SORT_DESC has no affect.
$dataProvider->setSort([
'attributes' => [
'fullName' => [
'asc' => ['first_name' => SORT_ASC],
'desc' => ['first_name' => SORT_DESC],
],
'created_at' => [
'asc' => ['created_at' => SORT_ASC],
'desc' => ['created_at' => SORT_DESC],
'default' => SORT_DESC,
],
'status' => [
'asc' => ['status' => SORT_ASC],
'desc' => ['status' => SORT_DESC],
],
'request' => [
'asc' => ['request' => SORT_ASC],
'desc' => ['request' => SORT_DESC],
],]
]);
- Pagination goes wonky after filtering. I have ‘pageSize’ => 10, which works until I do one or more column filters. Then it will show, for example, “1-2 of 3” or “1-7 of 18” when the total # number of records is 12.
It appears to be caused by having a column where each row is an array of tags. If I remove this from the gridview, the pagination works fine. Is there a way around this?
$query->joinWith(['tags' => function ($) {
$q->where(['like', 'tag', $this->tagName]);
}]);
-
Trouble accessing related records when filtering
'fullName' => [ 'asc' => ['first_name' => SORT_ASC], 'desc' => ['first_name' => SORT_DESC], ],
The filtering criteria:
$query->joinWith(['networkUser' => function ($q) {
$q->where(['like', 'first_name', $this->fullName]);
$q->orWhere(['like', 'last_name', $this->fullName]);
}]);
networkUser is a chained relation ($model->networkMember->user). The query works fine and I can var_dump the results to see that first_name and last_name are there as related records. But, I can’t get the sort to recognize them. I’ve tried many different ways: ‘networkUser.first_name’, user.first_name’, ‘first_name’, etc., but it always returns a “column not found error.”