Does cGridView exist in non-ajaxed version?

Please see end of this post.

I was trying to do make this work checking the dataProvider results. Anyone can help me here?

My cGridView:





<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'business-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'id',

                'name',

/////////

//////

///

?>



Below this I added code to view, to check the number of items returned by current dataProvider:




<?php

$dataProvider=$model->search();

echo $dataProvider->getItemCount();

////

?>



But it returns me whole number of items, I think because I call here $dataProvider=$model->search(); but I don;t know how to get to current state of $dataProvider (after filter applied).

Before filter:

After filter:

echo $dataProvider->getItemCount(); still displays 6 totalItems() of $dataProvider… anybody knows how to get to current state of $dataProvider?

Any help would be appreciated

Tom

Try this :




<?php $this->widget('zii.widgets.grid.CGridView', array(

        'id'=>'business-grid',

        'dataProvider'=>$model->search(),

        'filter'=>$model,

        'columns'=>array(

                'id',

                'name',

	),

	'afterAjaxUpdate'=>'function(id,data){	var rowCount = $("#"+id+" .items tbody tr").length; alert(rowCount); }',

)); ?>



Thanks! for helping on this. Now I get number of rows returned by $dataProvider after filter applied:

Do you think, I can pull out this variable $rowCount outside the cGridView widget? To echo some div underneath the grid while this $rowCount <> total rows of $dataProvider?

Well this solution is almost perfect. Almost, because when no records are found "No results" row is also treated as <tr> and rowCount returns "No results" as 1 row…

Any clues how to modify this line




'afterAjaxUpdate'=>'function(id,data){  var rowCount = $("#"+id+" .items tbody tr").length; alert(rowCount); }',



so it omits "No results" row?

Try this :




'afterAjaxUpdate'=>'function(id,data){  var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; alert(rowCount);  }',



Yup, it works that way! Great thanks.

But I am trying to get this value now in the body.




'afterAjaxUpdate'=>'

function(id,data)

{var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; document(rowCount); }

',



Gives me new empty page with this variable value:

There are 5 rows of type "Banking", but…

I also tried to


echo $_GET['rowCount'];

Without success. Any clues, how to get to this JavaScript variable by PHP?

In your "admin" page add a div with the id "rowCount"


<div id="rowCount"> </ div>

and change your code as follows:




'afterAjaxUpdate'=>'function(id,data){  var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; $("#rowCount").html(rowCount);  }',



Cordially.

Well I updated code to:


'afterAjaxUpdate'=>'function(id,data){  var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; $("#rowCount").html(rowCount);  }',

And added to the bottom of admin view:


<div id="rowCount"> </ div>

But then Operations standard menu from the right was moved to the bottom:

And what’s more how I can echo this value that is id of DIV?

can you show me the source code of the view "Admin" ?

Here is my admin.php:




<?php

$this->breadcrumbs=array(

	'Businesses'=>array('index'),

	'Manage',

);


$this->menu=array(

array('label'=>'Register Business', 'url'=>array('create')),

array('label'=>'Manage Businesses', 'url'=>array('admin')),

array('label'=>'Businesses Lists', 'url'=>array('lists')),

array('label'=>'List Businesses', 'url'=>array('index')),

);


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('business-grid', {

		data: $(this).serialize()

	});

	return false;

});

");

?>


<p>

You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

	'model'=>$model,

)); ?>

</div><!-- search-form -->


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'business-grid',

	'dataProvider'=>$model->search(),

	'afterAjaxUpdate'=>'function(id,data){  var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; $("#rowCount").html(rowCount);  }',

	'filter'=>$model,

	'columns'=>array(

		'id',

		array(              

	            'name'=>'active',

		    'header'=>'Status',

        	    'value'=>CHtml::encode(active?'Active':'Unactive'),

		),	

		'name',

		array(              

	        'name'=>'id_business_type',

			'header'=>'Business Type',

        	        'value'=>'$data->rel_id_business_type->name_en',

			'filter'=> DictBusinessTypes::items(),

		),		

		array(

			'class'=>'CButtonColumn',

		),

	),

));

?>

<div id="rowCount"> </ div>






<?php

$this->breadcrumbs=array(

        'Businesses'=>array('index'),

        'Manage',

);


$this->menu=array(

array('label'=>'Register Business', 'url'=>array('create')),

array('label'=>'Manage Businesses', 'url'=>array('admin')),

array('label'=>'Businesses Lists', 'url'=>array('lists')),

array('label'=>'List Businesses', 'url'=>array('index')),

);


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

        $('.search-form').toggle();

        return false;

});

$('.search-form form').submit(function(){

        $.fn.yiiGridView.update('business-grid', {

                data: $(this).serialize()

        });

        return false;

});

");

?>


<p>

You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

        'model'=>$model,

)); ?>

</div><!-- search-form -->

<div id="rowCount"> </ div>

<?php $this->widget('zii.widgets.grid.CGridView', array(

        'id'=>'business-grid',

        'dataProvider'=>$model->search(),

        'afterAjaxUpdate'=>'function(id,data){  var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; $("#rowCount").html(rowCount);  }',

        'filter'=>$model,

        'columns'=>array(

                'id',

                array(              

                    'name'=>'active',

                    'header'=>'Status',

                    'value'=>CHtml::encode(active?'Active':'Unactive'),

                ),      

                'name',

                array(              

                'name'=>'id_business_type',

                        'header'=>'Business Type',

                        'value'=>'$data->rel_id_business_type->name_en',

                        'filter'=> DictBusinessTypes::items(),

                ),              

                array(

                        'class'=>'CButtonColumn',

                ),

        ),

));

?>



Yup. That worked:

I wonder If we could access this variable from "Displaying 1-5 of 5 result(s)."?

Anyway, how I can echo this value? Or just access/check it by PHP? [color="#2E8B57"]If ($rowCount>0) {doSomething;}[/color]

@pc131 I would suggest you to take a learn on jQuery… so that you grasp at least the basics… wlil be more easyer for you… and try to understand what data is available to PHP (and when)… and what data is available to javascript/jQuery…

mdomba

Ok, I run maybe to far for this JQuery thing and passing this to PHP. I’m not that good at JQuery, so at beginning I wanted some help, how to get to the dataProvider [color="#0000FF"]itemCount[/color] property like defined in the reference. Believe me I always try to read reference and try to find solutions myself.

To be more precise, I didn’t know how to call this, current, just used in the CGridView widget ‘dataProvider’.

This one:

[size=“2”]<?[color="#FF0000"]php[/color] $[color="#0000FF"]this[/color]->widget(’[color="#696969"]zii.widgets.grid.CGridView[/color]’, array(

'[color=&quot;#696969&quot;]id[/color]'=&gt;'[color=&quot;#696969&quot;]business-grid[/color]',[/size]


'[size=&quot;5&quot;][color=&quot;#ff0000&quot;][b]dataProvider[/b][/color][/size]'=&gt;&#036;[color=&quot;#0000FF&quot;]model[/color]-&gt;search(),


[size=&quot;2&quot;]'[color=&quot;#696969&quot;]filter[/color]'=&gt;&#036;[color=&quot;#0000FF&quot;]model[/color],


'[color=&quot;#696969&quot;]columns[/color]'=&gt;array(


	'id',[/size]


    //more columns...

Thanks Mandi for you JQuery trick, in this code:


'function(id,data){  var rowCount = $("#"+id+" .items tbody tr:not(:has(span.empty))").length; $("#rowCount").html(rowCount);  }',

As I can suspect this function reads the rendered html, and counts items tr in tbody and omits empty ones.

[color="#008000"]However[/color] I wanted just get to the current dataProvider. Doing this:


$dataProvider=$model->search();

echo $dataProvider->itemCount;

gives me still total number of items in model, no matter if grid is filtered, which is obvious, because of the line above…

But if I try to echo:




echo $dataProvider->itemCount;



I get nothing, because [color="#9932CC"]$dataProvider[/color] seems to be not the same as this one below:

[size=“2”]<?[color="#FF0000"]php[/color] $[color="#0000FF"]this[/color]->widget(’[color="#696969"]zii.widgets.grid.CGridView[/color]’, array(

'[color=&quot;#696969&quot;]id[/color]'=&gt;'[color=&quot;#696969&quot;]business-grid[/color]',[/size]


'[size=&quot;5&quot;][color=&quot;#ff0000&quot;][b]dataProvider[/b][/color][/size]'=&gt;&#036;[color=&quot;#0000FF&quot;]model[/color]-&gt;search(),

Anyone?

Quick question? Does the cGridView in Yii 1.1.4 exist in non-ajaxed version?

Thanks,

Tom

You should set the property ajaxUpdate to false, in order to make pagination and sorting via standard request.