Pagination in JuiDialog

Hi All,

I am facing issue in pagination inside of JUIDialog.

My code is as

Controller




        public function actionAddbrands(){

            if(isset($_POST['BrandSupplier'])){

                foreach($_POST['BrandSupplier']['brands'] as $brand){

                            $exist=BrandSupplier::model()->findByAttributes(array('brand_id'=>$brand['id']));

                          if(!empty($exist))

                          $brandsupplier=new BrandSupplier;

                          $brandsupplier->brand_id=$brand['id'];

                          $brandsupplier->supplier_id=$_GET['supplier_id'];

                          $brandsupplier->save();

                }

                    echo CJSON::encode(array(

                        'status'=>'success', 

                        'div'=>"Items Added"

                        ));

                    exit;                  

                

                

            }

		if(Yii::app()->request->isAjaxRequest)

		{            

                    

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

            echo CJSON::encode(array(

                'status'=>'failure', 

                'div'=>$this->renderPartial('_brandsupplier', array(), true)));

            exit;    

                }

        }



Form




$brands=new Brands('search');

		$brands->unsetAttributes();  // clear any default values

		if(isset($_GET['Brands'])){

			$brands->attributes=$_GET['Brands'];

                }

                

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

	'id'=>'brands-grid',

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

	'filter'=>$brands,

    //    'ajaxUpdate'=>false,

	'columns'=>array(

		array(

                    'name'=>'name',

                    'type'=>'raw',

                 //   'value'=>'CHtml::checkBox("brands[]",null,array("value"=>$data->id,"id"=>"brand_".$data->id)).$data->name',

                    ),

		array(

			'class'=>'CButtonColumn',

		),

	),

));



On first type, it works fine

But when I click on pagination, it loads a normal page but not load contents on the JUIDialog.

Any help?

How can I set the value for CGridView in JUIDialog

I have analysis that pagination is not called by ajax, that’s the why it is loading in normal page.

Is there any way to fix it?

any help?

Hi Pero…

It is hard for anybody to help you my friend if you don’t post the code with your issue… I am not sure if what you expect is that when somebody clicks on a link (where?) it opens a dialog box? and when pagination occurs, that link is not working anymore right?

If that is the case, then I recommend you to include css classes to those links and then, ON FIRST PAGE rendering, you write the javascript functions that will handle the opening of dialogs by using DELEGATE or LIVE jQuery methods (one of the good guys in jQuery said that is better delegate than live but both would work). This way, even if your grid contents change via AJAX as they occur when you click pagination, the links will always work.

Cheers


Opps! Just understood that what you are trying to do is to update the grid within the JUIDialog… You need to process its output:




echo CJSON::encode(array(

                'status'=>'failure', 

                'div'=>$this->renderPartial('_brandsupplier', array(), true, TRUE)));



PS: I leave first answer as it is good info too

Thanks Antonio. I will try the code and will update you.

This is the code which is calling the JUIDialog.




<h1><?php echo $model->name; ?></h1>


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

	'data'=>$model,

	'attributes'=>array(

		'description',

		'website',

		'email',

		'phone',

		'ship_products_to',

		'action',

                array(

                    'name'=>'country',

                    'type'=>'raw',

                    'value'=>  Country::name($model->country)

                ),

                array(

                    'name'=>'state',

                    'type'=>'raw',

                    'value'=> CountryStates::name($model->state)

                ),

                array(

                    'name'=>'city',

                    'type'=>'raw',

                    'value'=>  CountryCity::name($model->city)

                ),  

                'zipcode',

                'address',

		'supplier_type',

                array(

                    'name'=>'general_category',

                    'type'=>'raw',

                    'value'=> SupplierCategory::ListCategories($model->categories)

                ),            

		'date'

	),

)); 

?>

<div class="span-8">

    <h3>Brands</h3>

 

 <?php 

echo CHtml::link('Add Brand From List', Yii::app()->createUrl("admin/suppliers/addbrands",array("supplier_id"=>$model->id)),  // the link for open the dialog

    array(

        'style'=>'cursor: pointer; text-decoration: underline;',

        'onClick'=>'calldialog._url= $(this).attr("href");

                calldialog._update="products-grid";

                calldialog();

                $("#calldialog").dialog("open");

                return false;'        

        )).' | ';


echo CHtml::link('Add New Brand', Yii::app()->createUrl("admin/brands/create",array('supplier_id'=>$model->id)),  // the link for open the dialog

    array(

        'style'=>'cursor: pointer; text-decoration: underline;',

        'onclick'=>"{

                calldialog._url= $(this).attr('href');

                calldialog._up;

                calldialog();

                $('#calldialog').dialog('open');

                return false;}"));




$criteria=new CDbCriteria;

$criteria->condition="supplier_id='".$model->id."'";

$states=new CActiveDataProvider('BrandSupplier', array(

			'criteria'=>$criteria,

                        'pagination'=>false

		));


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

	'id'=>'brandsuppliers-grid',

	'dataProvider'=>$states,

        'enablePagination'=>false,

	'columns'=>array(

		array(

                    'name'=>'name',

                    'type'=>'raw',

                    'value'=>'$data->brand->name'

                    ),           

array

(

    'class'=>'CButtonColumn',

    'template'=>'{delete}',

    'buttons'=>array

    (

        'delete' => array

        (

            'label'=>'Delete',

            'url'=>'Yii::app()->createUrl("/admin/suppliers/deletebrand",array("id"=>$data->brand_id,"supplier_id"=>$data->supplier_id))',

        ),        

    ),

)

	),

)); 


?>


 

</div>

<div class="span-8">

    <h3>Products</h3>

<?php 

echo CHtml::link('Add Products From List', Yii::app()->createUrl("admin/suppliers/addproducts",array("supplier_id"=>$model->id)),  // the link for open the dialog

    array(

        'style'=>'cursor: pointer; text-decoration: underline;'

        )).' | ';


echo CHtml::link('Add New Product', Yii::app()->createUrl("admin/products/create",array('supplier_id'=>$model->id)),  // the link for open the dialog

    array(

        'style'=>'cursor: pointer; text-decoration: underline;',

        'onclick'=>"{

                calldialog._url= $(this).attr('href');

                calldialog._up;

                calldialog();

                $('#calldialog').dialog('open');

                return false;}"));




$criteria=new CDbCriteria;

$criteria->condition="supplier_id='".$model->id."'";

$states=new CActiveDataProvider('ProductSupplier', array(

			'criteria'=>$criteria,

                        'pagination'=>false

		));


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

	'id'=>'products-grid',

	'dataProvider'=>$states,

        'enablePagination'=>false,

	'columns'=>array(

		array(

                    'name'=>'name',

                    'type'=>'raw',

                    'value'=>'$data->product->name'

                    ),           

array

(

    'class'=>'CButtonColumn',

    'template'=>'{delete}',

    'buttons'=>array

    (

        'delete' => array

        (

            'label'=>'Delete',

            'url'=>'Yii::app()->createUrl("/admin/suppliers/deleteproduct",array("id"=>$data->product_id,"supplier_id"=>$data->supplier_id))',

        ),        

    ),

)

	),

)); 


?>    

</div>




<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

    'id'=>'calldialog',

    'options'=>array(

        'title'=>$model->name,

        'autoOpen'=>false,

        'modal'=>true,

        'width'=>700,

        'height'=>500,

    ),

));?>

<div class="calldialog"></div>

 

<?php $this->endWidget();?>

 

<script type="text/javascript">

function calldialog()

{

    // public property

    var _url;

    var _update;

    <?php echo CHtml::ajax(array(

        'url'=>'js:calldialog._url',

        'data'=> "js:$(this).serialize()",

        'type'=>'post',

        'dataType'=>'json',

        'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#calldialog div.calldialog').html(data.div);

                    // Here is the trick: on submit-> once again this function!

                    $('#calldialog div.calldialog form').submit(calldialog);

                }

                else

                {

                    $('#calldialog div.calldialog').html(data.div);

                    $.fn.yiiGridView.update(calldialog._update);                     

                    $('#calldialog').dialog('close');


                   

                }

 

        } ",

    ))?>;

    return false;

 

}




 

</script>