php - Yii2 Distinct Rows in gridview -


i unable unique results in grid view.

what have done far is:

$query = products::find()->select('id_product_provider')->distinct(); $dataprovider = new activedataprovider([         'query'      => $query,         'pagination' => [             'pagesize' => 100         ]     ]); 

the result wanted, grid view not showing other columns some-column,

output: enter image description here dont know, result wanted be. grid view not showing other required colums name, description etc.

i update query following:

$query = products::find()->select('other_columns,some_column')->distinct(); 

the result not unique some_column. enter image description here

controller code:

$searchmodel  = new productssearch();         $dataprovider = $searchmodel->search(yii::$app->request->queryparams);          return $this->render('index', [             'searchmodel'  => $searchmodel,             'dataprovider' => $dataprovider,         ]); 

and view is:

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}&nbsp;&nbsp;&nbsp;{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']);                                                                   }],]],]);         ?> 

any appreciated.

the result distinc combination of columns provided in select (and not some_column)

in case $query = products::find()->select('other_columns,some_column')->distinct(); other_columns, some_column-

you can check query executed using

  var_dump(products::find()->select('other_columns,some_column')->distinct()       ->createcommand()->getsql()); 

then query should be

$query = products::find()->      select('name,  description, price, price_category')->distinct(); 

but if need rows shuld use aggregation function , group not distinct

$query = products::find()->      select('max(name) name,             max(description) description,           max(price) price,            max(price_category) price_category ')->groupby(['id_product_provider']); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -