Yii Framework Forum: Widget-Dataprovider-Count same rows - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Widget-Dataprovider-Count same rows NGridview from $model and Count the same rows Rate Topic: -----

#1 User is offline   Jedi19871109 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 05-October 17

Posted 24 October 2017 - 08:04 AM

Hi Yii Masters!

I have a problem, what i cant solve it. I tried search the solution, but i cant find it (of course that is my mistakes ^^').
So I have a Datagridview from $model, which show a Cars and Owners.
I want counting the same rows (see below the sample what i want)



<?php
$this->widget('application.extensions.NPager.NGridView', array(
'id' => 'Car-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'ajaxUrl' => $this->ajaxUrl,

'cssFile' => Yii::app()->baseUrl . '/css/gridview/styles.css',
'template' => '{summary}{pagerlist}{pager}{items}{pager}',
'pagerlist' => array(
'8' => '8',
'10' => '10',
'25' => '25',
'50' => '50',
'100' => '100',
),
'textItemsPerPage' => 'per side',
'columns' => array(
array(
'name' => 'Owner',
'header' => 'Owner',
'type' => 'raw',
'filter' => CHtml::activeTextField($model, 'searchid', array('id'=>'Owner_tb'),
),

array(
'name' => 'Car',
'header' => 'Car',
'value' => '(is_object($data->car),
'type' => 'raw',
'filter' => CHtml::activeTextField($model, 'searchcar','id'=>'Car_tb'),
);
array(
'name' => 'Count',
'header' => 'Count',
'value' => ???????
'type' => 'raw',

);

?>

My result :
---------------------------------
Owner | Car
---------------------------------
Peter Company | BMW
Johs Company | Volvo
Peter Company | BMW
---------------------------------

And what i want :
------------------------------------------------
Owner | Car | Count
------------------------------------------------
Peter Company | BMW | 2
Johs Company | Volvo | 1
-----------------------------------------------

Sorry for my bad english, but i hope its understandable :)
Thank you :)
0

#2 User is offline   Jedi19871109 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 05-October 17

Posted 25 October 2017 - 07:16 AM

Through this i can solved the problem !

<?php
$rawData=Yii::app()->db->createCommand('SQL COMMAND PLACE')->queryAll();
$dataProvider = new CArrayDataProvider($rawData);
$dataProvider->setData($model->productitemid);

$model->setAttributes($rawData);
$newDataProvider=$model->search();

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'product-grid',
'dataProvider' => $model->search(),
'ajaxUrl' => $this->ajaxUrl,
'cssFile' => Yii::app()->baseUrl . '/css/gridview/styles.css',
'template' => '{summary}{pagerlist}{pager}{items}{pager}',

));
?>


^^ thank you who read my post *.*
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users