그리드보기에서 고유 한 결과를 가져올 수 없습니다.Yii2 gridview의 고유 행
$query = Products::find()->select('id_product_provider')->distinct();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 100
]
]);
결과는 내가 원한하지만, 그리드보기
는출력, some-column
보다 다른 모든 열 표시되지 않습니다 : 내가 지금까지했던 어떤
이다 나는 잘 모릅니다 , 결과는 내가 원했던 것이다. 그러나 그리드 뷰는 다음에 등 이름, 설명
내가 쿼리를 업데이트 등의 다른 모든 필수 colums 표시되지 않습니다 :
$query = Products::find()->select('other_columns,some_column')->distinct();
결과가 some_column
에 의해 고유하지 않습니다.
컨트롤러 코드 :
$searchModel = new ProductsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
그리고보기는 다음과 같습니다
GridView::widget(['dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [['class' => 'yii\grid\SerialColumn'],
['attribute' => 'Image',
'format' => 'html',
'value' => function ($data) {
return Html::img($data->image, ['width' => '100']);
},],
['attribute' => 'name',
'format' => 'raw',
'value' => function ($data) {
return strlen($data->name) > 25 ?
html_entity_decode(substr($data->name, 0, 25) . '...') :
html_entity_decode($data->name);
},
'contentOptions' => ['style' => 'max-width: 200px;']],
['attribute' => 'description',
'format' => 'raw',
'value' => function ($data) {
return strlen($data->description) > 25 ?
html_entity_decode(substr($data->description, 0, 25) . '...') :
html_entity_decode($data->description);
},
'contentOptions' => ['style' => 'max-width: 200px;']],
['attribute' => 'price',
'format' => 'text',
'value' => function ($data) {
return html_entity_decode($data->price);
},],
['attribute' => 'price_category',
'format' => 'text',
'value' => function ($data) {
return strip_tags(html_entity_decode($data->price_category));
},
'contentOptions' => ['style' => 'max-width: 100px;']],
['attribute' => 'product_category',
'format' => 'text',
'filter' => $categories,
'value' => function ($data) {
return strlen($data->product_category) > 25 ?
html_entity_decode(substr($data->product_category, 0, 25) . '...') :
html_entity_decode($data->product_category);
},
'contentOptions' => ['style' => 'max-width: 150px;']],
['attribute' => 'provider',
'format' => 'text',
'value' => function ($data) {
return strlen($data->provider) > 25 ?
html_entity_decode(substr($data->provider, 0, 25) . '...') :
html_entity_decode($data->provider);
},
'contentOptions' => ['style' => 'max-width: 150px;'],
'filter' => $providers,],
['attribute' => 'universe',
'format' => 'text',
'contentOptions' => ['style' => 'max-width: 100px;'],
'filter' => ['fabrics' => 'fabrics', 'wool' => 'wool', 'paper' => 'paper'],],
'id_product_provider',
['class' => 'yii\grid\ActionColumn',
'header' => 'Action',
'template' => '{info} {detail}',
'buttons' => ['info' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon glyphicon-eye-open"></span>', $model->url, ['title' => Yii::t('app', 'Info'),
'target' => '_blank']);
},
'detail' => function ($url, $model) {
$url = str_replace(' ', '-', $model->universe) . '/' . str_replace(' ', '-', $model->product_category) . '/' . $model->slug . '/' . $model->id;
$url = Yii::$app->urlManagerFrontEnd->createUrl($url);
return Html::a('<span class="glyphicon glyphicon glyphicon glyphicon-picture"></span>', $url, ['title' => Yii::t('app', 'Info'),
'target' => '_blank']);
}],]],]);
?>
어떤 도움을 이해할 수있을 것이다.
그래, 난 그냥 하나의 열을 기준으로 uniness 필요하지만, 그리드보기에서 모든 열을 표시하지 않음으로써 집계 함수 및 그룹을 사용 shuld. 그게 나타나지 않아. – TNC
나는 이해하지 못한다. 적절한 데이터 샘플 e와 예상되는 질문으로 업데이트해야한다. 결과 .. – scaisEdge
격자보기가 다른 모든 열을 표시하지는 않지만 식별 열만 표시합니다. – TNC