Yii Framework Forum: Criteria In Carraydataprovider - Yii Framework Forum

Jump to content

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

Criteria In Carraydataprovider Rate Topic: -----

#1 User is offline   Javed Iqbal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 25-October 11

Posted 21 March 2014 - 10:45 AM

I have used CArrayDataProvider as dataprovider for bootstrap.widgets.TbGridView.I want to filter data as we can do with CActiveDataProvider.

View (admin.php)
$vQ = 'SELECT sl.sale_date AS SaleDate, sl.discount AS Discount,
st.stock_out AS StockOut,
st.sale_price AS SalePrice,
 (st.stock_out * st.sale_price) AS SaleAmount,
pd.name AS ProductName,
cl.name AS ClientName 
FROM tbl_sale sl
left outer join tbl_stock st on st.master_id = sl.id
left outer join tbl_products pd on pd.id = st.product_id
left outer join tbl_clients cl on cl.id = sl.client_id
WHERE sl.edt IS NULL
AND st.edt IS NULL
AND pd.edt IS NULL

';
$command = Yii::app()->db->createCommand($vQ);
$aRes = $command->queryAll();
foreach ($aRes as $thisRow) {
	$rawData[] = array('id'=>1, 'SaleDate'=>$thisRow['SaleDate'], 'ClientName'=>$thisRow['ClientName']);
}
$arrayDataProvider=new CArrayDataProvider($rawData, array(
		'id'=>'id',
		'keyField'=>'id',
// 		'criteria'=>$criteria, //this gives error
		'sort'=>array(
			'attributes'=>array(
					'sale_date', 'client_id',
			),
		),
		'pagination'=>array(
				'pageSize'=>10,
		),
));

Yii::import('ext.chosen.Chosen');
$this->widget('bootstrap.widgets.TbGridView', array(
		'type'=>'striped bordered condensed',
		'filter'=>$model,
		'dataProvider' => $arrayDataProvider,
		'columns' => array(
				array(
						'name' => 'sale_date', 'header'=>'Sale Date',
						'type' => 'raw',
						'value' => 'CHtml::encode($data["SaleDate"])',
				),
				array(
						'name' => 'client_id', 'header'=>'Client',
						'type' => 'raw',
						'value' => 'CHtml::encode($data["ClientName"])',
						'filter'=> Chosen::activeDropDownList($model, "client_id",  CHtml::listData(Clients::model()->findall("edt IS NULL ORDER BY name"), 'id', 'name'),  array('class'=>'chosen')),
				),
		),
));

Javed Iqbal

Web Developer
syntecX Solution
skype:javedboqo
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