Hi
How can i get total number of records in cgridview? i have to show total number of records on the top of list.so please tell me how can i get it in view file.thanks
Page 1 of 1
How Can I Get Total Number Of Records In Cgridview? How can i get total number of records in cgridview?
#2
Posted 26 November 2012 - 08:29 AM
Hi
you can get the count of records by the related CDataProvider of CGridview
$yourprovider->getItemCount()
$yourprovider->getTotalItemCount(); //(idepended of pagination)
or you can get it by count($yourprovider->->getData())
you can get the count of records by the related CDataProvider of CGridview
$yourprovider->getItemCount()
$yourprovider->getTotalItemCount(); //(idepended of pagination)
or you can get it by count($yourprovider->->getData())
#3
Posted 20 December 2012 - 01:35 AM
Hi KonApaz
thanks for your reply. as i am a new to yii can you explain a bit more as where to write these functions call, in model or controller? and how can i access these values in view.thanks
thanks for your reply. as i am a new to yii can you explain a bit more as where to write these functions call, in model or controller? and how can i access these values in view.thanks
#4
Posted 22 December 2012 - 04:00 PM
prashant.tyagi, on 20 December 2012 - 01:35 AM, said:
Hi KonApaz
thanks for your reply. as i am a new to yii can you explain a bit more as where to write these functions call, in model or controller? and how can i access these values in view.thanks
thanks for your reply. as i am a new to yii can you explain a bit more as where to write these functions call, in model or controller? and how can i access these values in view.thanks
the think you have to do for any part of code (in most cases) :
Is it about display ?
Is it about logic (checking, decision and control) ?
Is it about fetching data ?
All the above things called MVC (Model viewer, controller)
So create the dataprovider in Controller with all its parameters
(in order the CActiveDataProvider fetch the data from model) and pass it in the viewer
example:
in Controller
public function actionIndex() {
$dataProvider = new CActiveDataProvider('YourModel')
$this->render('index', array('dataProvider' => $dataProvider));
}
in viewer (index)
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
#5
Posted 30 January 2013 - 11:20 PM
thanks,but my dataprovider is a function like this
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'wishlist-grid',
'dataProvider'=>$model->xxxxxxxxx($xxxx,$yyyy),
'ajaxUpdate'=>false,
'columns'=>$attributes,
'filter'=>$model,
));
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'wishlist-grid',
'dataProvider'=>$model->xxxxxxxxx($xxxx,$yyyy),
'ajaxUpdate'=>false,
'columns'=>$attributes,
'filter'=>$model,
));
?>
#7
Posted 01 February 2013 - 03:01 PM
Dear Prasanth
I am just confused. CgridView already displays dynamically before filtering and also after filtering as summary. at the top right.
OK.Anyway things are easy because you have disabled ajaxUpdate.
Just insert the first two lines of the following code above the widget code.
If you want the same functionality with ajax enabled, we have to overide the CGridView.
components/GridView.php
Now admin.php uses this derived class with ajax enabled.
I hope I helped a bit.
Regards.
I am just confused. CgridView already displays dynamically before filtering and also after filtering as summary. at the top right.
OK.Anyway things are easy because you have disabled ajaxUpdate.
Just insert the first two lines of the following code above the widget code.
<?php
$total=$model->search()->getTotalItemCount();
echo "<h6>Total number of Items: ".$total."</h6>";
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'worker-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'ajaxUpdate'=>false,
'columns'=>array(
'id',
'name',
'assigned',
'completed',
'g_id',
array(
'class'=>'CButtonColumn',
),
),
));
?>
If you want the same functionality with ajax enabled, we have to overide the CGridView.
components/GridView.php
<?php
Yii::import('zii.widgets.grid.CGridView');
class GridView extends CGridView
{
public function run()
{
$this->registerClientScript();
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$total=$this->dataProvider->getTotalItemCount();//added line
echo "<h6>Total number of Items: ".$total."</h6>";//added line
$this->renderContent();
$this->renderKeys();
echo CHtml::closeTag($this->tagName);
}
}
?>
Now admin.php uses this derived class with ajax enabled.
<?php $this->widget('GridView', array( //instance of GridView
'id'=>'worker-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'ajaxUpdate'=>true, //AJAX enabled
'columns'=>array(
'id',
'name',
'assigned',
'completed',
'g_id',
array(
'class'=>'CButtonColumn',
),
),
));
I hope I helped a bit.
Regards.
Share this topic:
Page 1 of 1

Help












