Progress Bar In Pagination

I have a _view.php page which displays items from database, one of things that is displayed is progress bar

But when pagination occurs, when i click next page, there is no progress bar rendered, when i go back to the first page it doesn’t render previously rendered progress bars.

This is what I use to render each item:


    

//I calculate the $pb_value in

    <div class="projectstat">

     $this->widget('zii.widgets.jui.CJuiProgressBar', array(

      'value'=>$pb_value,

      'htmlOptions'=>array(

       'style'=>'height:20px; width:204px; margin:auto; display:block;'

       ),

       ));?>

   </div>



What is the problem here? I guess pagination somehow ruins the progress bar logic?

Sort of, but it’s JS code in general, so you have to register again your JS codes in the afterAjaxUpdate property

Yes, it is the solution. but, how should that function look like? Can you provide some simple example?

My controller is making dataprovider, it is rendered in CListView using _view.php from index.php

Once page is rendered, $this->widget() code I posted above, which is located in _view.php produces divs which are named yw1, yw2, yw3… and yw0 is div which holds all items.

I managed to reinit the progress bar putting something like this

$(#yw1).progressbar({‘value:0’})

$(#yw2).progressbar({‘value:0’})

.

.

.

into afterajaxupdate property, but I calculate values in php, from certain data I have from database.

TL;DR; i can get progressbars to show up, but I can’t reinit their values.

So you returns values in PHP? Good. You can either return them in a JSON array and use them in your JS code, or even write them into hidden divs.

If you still can’t see how to do it, please post your relevant view(s) and controller codes.

Ohhh I got stuck, I need to reinit my progress bars but can’t quite get it.

This is my index.php (from view directory):




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

	'dataProvider'=>$dataProvider,

	'afterAjaxUpdate' => 'reinstallProgressBar',

	'itemView'=>'_view',

	'sortableAttributes'=>array(

        'name',

        // 'location->location_name'=>'Location',

        'idcategory',

    ),

	'template'=>'{sorter}{items}<br style="clear:both"><div style="margin-top:20px !important;>"{pager}{summary}</div>',

    'pager' => array('header'=>'',),

	'summaryText'=>'',

)); ?>

</div>

<?php echo $this->renderPartial('../layouts/sidebar_cat'); ?>


<?php 

Yii::app()->clientScript->registerScript('re-install-progress-bar', "

function reinstallProgressBar(id, data) {

    jQuery('#yw1').progressbar({'value':0});

    jQuery('#yw2').progressbar({'value':0});

    jQuery('#yw3').progressbar({'value':0});

    jQuery('#yw4').progressbar({'value':0});

    jQuery('#yw5').progressbar({'value':0});

    jQuery('#yw6').progressbar({'value':0});

    //alert(id);

    // alert(data);

}

");

?>



This is my _view.php




 <?php

      $pb_value=0;

      if($data->funding->current_funds <= $data->funding->funding_goal)

      {

        $pb_value = (($data->funding->current_funds * 100) / $data->funding->funding_goal);

      }

      else

      {

        $pb_value=100;

     }

     $this->widget('zii.widgets.jui.CJuiProgressBar', array(

      'value'=>$pb_value,

      'htmlOptions'=>array(

       'style'=>'height:20px; width:204px; margin:auto; display:block;'

       ),

       ));?>



As you can see, my progress bar value is calculated in _view.php file, but afterajaxupdate calls reinstallprogressbar in index.php, and I can not pass values to it in order to correctly reinit progress bars, (they are re-initalised, but I can not get the values, they are all = 0).