Search code examples
ajaxyiicgridviewcjuidialog

Yii CGridView rendered inside CJuiDialog won't be filtered or ordered


I'm rendering a CGridView inside a CJuiDialog, and that's working fine.

My problem is, every time i click a column header to sort records, the page changes (the url is the url of the view rendered with renderPartial through ajax) and the request is not ajax ( Yii::app()->request->isAjaxRequest inside the controller is false).

Also, if i filter any field, nothing happens.

How can I let the user sort or filter the CGridView?

OR: Is there another way to let the user choose a Foreign Key field through a CGridView?


Solution

  • I finally found the solution.

    When you call renderPartial you must set the 3rd parameter = FALSE and the 4th parameter = TRUE.

    $this->renderPartial('ajax_view',array(
                'model'=>$model,
                'dataProvider'=>$dataProvider,
                ),false,TRUE);
    

    From the official documentation:

    $return boolean whether the rendering result should be returned instead of being displayed to end users $processOutput boolean whether the rendering result should be postprocessed using processOutput.

    And the MOST IMPORTANT TWEAK: Inside the view rendered with renderPartial you must add:

    Yii::app()->clientscript->scriptMap['jquery.js'] = false;
    

    The page is reloaded simply 'cause jquery was loaded multiple times.