Yii Framework Forum: CGridView via Ajax - error displaying pages/sorting - Yii Framework Forum

Jump to content

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

CGridView via Ajax - error displaying pages/sorting Rate Topic: -----

#1 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 24 March 2010 - 10:25 AM

I'm trying to build a dynamic reporting section for my application ( using 1.1.1 )

I have the main index action for this controller creating a dual column display, in which the right column renders a partial _form. The _form submits via ajax to the left column div and displays the report details in a CGridView.

The initial ajax based partial render is called as such:

public function actionView()
{
   $reportOpt =new ReportsForm;
   ...  // basic init. for reportOpt 

   $dataProvider =new CActiveDataProvider('reportSummary', array(
					'pagination'=>array(
						'pageSize'=>10,
					)

				));

   $this->renderPartial( 
           "_".ReportsForm::$_reportTypes[$reportOpt->reportType]['action'],
           array('formOptions'=>$reportOpt, 'dataProvider'=>$dataProvider), 
           false, 
           true);
}


In the partial view:
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$dataProvider,
	'ajaxUpdate'=>'ajaxContent',
	)
);


To this point, everything works great.

However, whenever I try to use the column sorting and pagination, it displays the loading icon, then the div is updated with no content.

I feel like I must be missing something very basic and wonder if anyone can point me in the right direction please.
0

#2 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 27 March 2010 - 05:36 PM

Ok, I don't know if I'm just doing something so off the wall that no one else would bother, but just in case someone else is trying to do similar, I ended up using the following solution:

Quick Recap: Right side of page is form options (search criteria) which I don't wish to generate each time, Left side of page is resulting report display from DB data in a CGridView format.

In my Controller, I added a loadModel function to be used for all the actions to get the proper form data. Then I set the loadModel up as follows (note, requires configuring site cache):

public function loadModel()
{

    if ( $this->_model === null )
    {
        $this->_model = new ReportsForm;
        
        if ( isset($_POST['ReportsForm']))
        { 
            $this->_model->dtEnd=$_POST['ReportsForm']['dtEnd'];
            .... // etc. all form options
            // THIS IS THE KEY - cache the model
            Yii::app()->cache->set('report_form', $this->_model );

        } else {
            $this->_model->defaults(); // call up my preset default form options jic this is first time
            if ( $tmp = Yii::app()->cache()->get('report_form') )
               $this->_model = $tmp;
        }
    }
    return $this->_model;
}


Now the ajax updated view always has access to the form fields.

Can anyone see any major flaw in this plan which I might be overlooking in my Yii-noobness?
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