Yii Framework Forum: Update CGridView from CJuiDialog - Yii Framework Forum

Jump to content

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

Update CGridView from CJuiDialog javascript error: $.fn.yiiGridView is undefined Rate Topic: -----

#1 User is offline   psikocrisis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-July 10
  • Location:Madrid / Sardinia

Posted 31 August 2010 - 12:03 PM

Hola chicos,

He buscado dentro del forum y he encontrado algo parecido pero no he podido encontrar una solución a esto...

Básicamente tengo una vista principal con un formulario que guarda los datos de un modelo (Event). Dentro de esta vista necesito poder gestionar los datos de otro modelo (Ticket) que esta relacionado al primero. Así que he insertado dentro de la vista principal una CGridView que me lista todos los tickets de un evento. Para que las operaciones como 'insertar nuevo ticket' o 'modificar ticket' se puedan hacer dentro de la misma pagina he implementado un CJuiDialog. Bueno, hasta aquí todo bien, pero después que los datos se guardan, la CGridView de la pagina principal debería actualizarse y aquí está el problema...

Os enseño mi código:

View principal:
$form=$this->beginWidget('CActiveForm', array(
	'id'=>'event-form',
        'enableAjaxValidation'=>true,
));

...
...

$this->widget('zii.widgets.grid.CGridView', array(
            'dataProvider'=>$dataProvider,
            'id'=>'ticket-grid',
            'ajaxUpdate'=>true,
            'emptyText'=>'Ningun ticket añadido',
            'enablePagination'=>false,
            'enableSorting'=>true,
            'columns'=>array(
                'Nombre',
                'Precio',
                'Cantidad',
                array(
                    'type'=>'raw',
                    'value'=>'CHtml::ajaxLink("Update",
                              Yii::app()->createUrl("ticket/ajaxupdate",array("id"=>$data->primaryKey)), //TODO
                              array(
                                "type" => "POST",
                                "update"=>"#ticketDialogContainer",
                                "data" => array("eventid" =>"'.$model->Id.'")
                              ),
                              array( //htmlOptions
                                "class" =>"updateTicketDialog",
                              )
                            )',
                ), 
            )
        ));

...
...


            <div id="ticketaddarea">                
                <div id="ticketDialogContainer"></div>
            </div>


$this->endWidget();




View del CJuiDialog:

$form=$this->beginWidget('CActiveForm', array(
    'id'=>'ticket-form',
    'enableAjaxValidation'=>true,
));

...
...

    <div class="row buttons">
        <?php
        if($model->isNewRecord){
            $label = 'Create';
            $url = 'ticket/ajaxadd';
        }else{
            $label = 'Save';
            $url = 'ticket/ajaxupdate';
        }

        echo CHtml::ajaxSubmitButton($label, CHtml::normalizeUrl(array($url, 'id'=>$model->Id, 'render'=>false)),
                array('success'=>'js:function(data) {
                        $("#ticket-grid").yiiGridView.update("ticket-grid");
                        $("#ticketDialog").dialog("close");
                }'),
                array('id'=>'closeTicketDialog','type'=>'submit','name'=>'closeTicketDialog'));
        ?>
    </div>

...
...

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



Al enviar el formulario me sale el siguiente error:

$.fn.yiiGridView is undefined

No se si me estoy equivocando en algo pero no veo cual es el problema :huh:

Alguien sabe como puedo solucionar esto? Gracias!
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 01 September 2010 - 02:52 AM

Uhm... this is the english section of the forum :)
0

#3 User is offline   psikocrisis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-July 10
  • Location:Madrid / Sardinia

Posted 01 September 2010 - 03:08 AM

View PostMike, on 01 September 2010 - 02:52 AM, said:

Uhm... this is the english section of the forum :)


Ooops! Sorry! :D

Translated version:

Hi guys,

I have looked into the forum and found some post similar but I couldn't find a solution...

Basically I have a main view with a form that saves data for the model "Event." Within this view need to manage the data of another model "Ticket", which is related to the first. So I inserted a CGridView into the main view that lists all the tickets for an Event. For operations such as insert new ticket or change ticket can be made within the same page I implemented a CJuiDialog. Well, so far so good, but after the data is stored, the CGridView of the homepage should be updated and here's the problem...

my code:

Main View
$form=$this->beginWidget('CActiveForm', array(
	'id'=>'event-form',
        'enableAjaxValidation'=>true,
));

...
...

$this->widget('zii.widgets.grid.CGridView', array(
            'dataProvider'=>$dataProvider,
            'id'=>'ticket-grid',
            'ajaxUpdate'=>true,
            'emptyText'=>'Ningun ticket añadido',
            'enablePagination'=>false,
            'enableSorting'=>true,
            'columns'=>array(
                'Nombre',
                'Precio',
                'Cantidad',
                array(
                    'type'=>'raw',
                    'value'=>'CHtml::ajaxLink("Update",
                              Yii::app()->createUrl("ticket/ajaxupdate",array("id"=>$data->primaryKey)), //TODO
                              array(
                                "type" => "POST",
                                "update"=>"#ticketDialogContainer",
                                "data" => array("eventid" =>"'.$model->Id.'")
                              ),
                              array( //htmlOptions
                                "class" =>"updateTicketDialog",
                              )
                            )',
                ), 
            )
        ));

...
...


            <div id="ticketaddarea">                
                <div id="ticketDialogContainer"></div>
            </div>


$this->endWidget();




Partial view - CJuiDialog:

$form=$this->beginWidget('CActiveForm', array(
    'id'=>'ticket-form',
    'enableAjaxValidation'=>true,
));

...
...

    <div class="row buttons">
        <?php
        if($model->isNewRecord){
            $label = 'Create';
            $url = 'ticket/ajaxadd';
        }else{
            $label = 'Save';
            $url = 'ticket/ajaxupdate';
        }

        echo CHtml::ajaxSubmitButton($label, CHtml::normalizeUrl(array($url, 'id'=>$model->Id, 'render'=>false)),
                array('success'=>'js:function(data) {
                        $("#ticket-grid").yiiGridView.update("ticket-grid");
                        $("#ticketDialog").dialog("close");
                }'),
                array('id'=>'closeTicketDialog','type'=>'submit','name'=>'closeTicketDialog'));
        ?>
    </div>

...
...

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



By submitting the 'ticket-form' I get the following error:

$. fn.yiiGridView is undefined :(

I don't know if I'm doing something wrong and what the problem is: huh:

Anyone know how I can fix this?

Thanks!
0

#4 User is offline   psikocrisis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-July 10
  • Location:Madrid / Sardinia

Posted 25 October 2010 - 04:15 AM

This is problem is caused because there is a bug in CClientScript...
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