Cgridview Page Change Help

I have a question about how to properly use CGridView in my particular case. I have a view with two elements: an image and a CGridView:

view.php




<html>

  <body>

    <img src="<?php echo $imgURL; ?>" />

    <?php

    this->widget("zii.widgets.grid.CGridView", array(

      "dataProvider" => $dataProvider,

      "columns" => $columns

    ));

    ?>

  </body>

</html>



In my controller, it does some work generating an image (and returns the URL so it can be displayed in the view), and at times this can take a few seconds depending on how large the $dataProvider output is. When I change pages in the CGridView it’s performing an AJAX call and loads the whole page, so that image is getting generated each time the user clicks a page number.

What would be the proper way to handle the CGridView here as to not regenerate the image each time the page is changed? I’m new to Yii (if that wasn’t obvious) but not to PHP. Any help or insights would be greatly appreciated.

Hi and welcome to the Yii forum

You did not show your code that the question is about (generating the image path)… but the only solution I can think of is to store the generated path in the table, this way you don’t need to generate it every time…

Hi,

Try this

http://www.yiiframework.com/wiki/520/how-to-avoid-rendering-entire-page-on-ajax-call-for-cgridview-and-clistview/

OR

http://www.yiiframework.com/wiki/163/avoiding-rendering-entire-page-when-using-cgridview-and-clistview-via-ajax/

Happy coding :)

That first link looks like it should do the job. Thanks a lot for pointing it out, I appreciate it!