2015-06-09 196 views
0

我想通过点击CGridView CButtonColumn视图按钮我CGridView和CJuiModel打开CJuiModel如: -Ajax请求不工作CGridView更新后

 <?php 
       $dataProvider = new CArrayDataProvider($model->exhibitorLocation, array(
        'keys' => array('productId'), 
       )); 


       $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $dataProvider, 
        'id' => 'exhibitor-location-grid', 
        'summaryText' => false, 
        'pager' => array(
         'class' => 'CLinkPager', 
         'header' => false, 
        ), 
        'columns' => array(
         array(
          'header' => 'S No.', 
          'value' => '++$row', 
         ), 
         array(
          'header' => 'Hall No', 
          'value' => '$data->location->hallNo', 
         ), 
         array(
          'header' => 'Stand No', 
          'value' => '$data->standNo', 
         ), 
         array(
          'class' => 'CButtonColumn', 
          'header' => 'Manage', 
          'template' => '{view}{delete}', 
          'buttons' => array(
           'view' => array(
            'imageUrl' => $this->module->assetsUrl . "/images/info_icon.png", 
            'options' => array('class' => 'exb-location'), 
            'url' => 'Yii::app()->createUrl("admin/venuemap/viewExbLocation", array("exbLocId"=>$data->primaryKey))', 
           ), 
           'delete' => array(
            'imageUrl' => $this->module->assetsUrl . "/images/delete_icon.png", 
            'url' => 'Yii::app()->createUrl("admin/venuemap/deleteExbLocation", array("exbLocId"=>$data->primaryKey))', 
           ), 
          ), 
          'htmlOptions' => array(
           'style' => 'width:100px;float:center' 
          ) 
         ), 
        ), 
        'rowCssClassExpression' => '($row%2 ? "visit2" : "visit1")', 
        'itemsCssClass' => 'visitor_list', 
        'htmlOptions' => array(
        ) 
       )); 
       ?> 
       <div class="name_field">Hall No<span>*</span></div> 
       <?php echo CHtml::dropDownList('hall-no', '', CHtml::listData(Venuemap::model()->findAll(), 'locationId', 'hallNo'), array('class' => 'name_input2', 'id' => 'hall-no')); ?> 

       <div class="name_field">Stand No</div> 
    <?php echo CHtml::textField('Stand No', '', array('class' => 'name_input', 'id' => 'stand-no')); ?> 

       <?php 
       echo CHtml::ajaxLink("Add Location", Yii::app()->createUrl('admin/venuemap/addExbLocation'), array(
        'type' => 'post', 
        'data' => array(
         'exhibitorId' => $model->exhibitorId, 
         'standNo' => 'js: $("#stand-no").val()', 
         'locationId' => 'js: $("#hall-no").val()' 
        ), 
        'success' => 'function(html){ $.fn.yiiGridView.update("exhibitor-location-grid"); }' 
         ), array('class' => 'search_btn')); 
       ?> 

       <?php 
        $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
         'id' => 'location-dialog', 
         'options' => array(
          'title' => 'View Location', 
          'autoOpen' => false, 
          'modal' => true, 
          'width' => 'auto', 
          'height' => 'auto', 
          'resizable' => false 
         ), 
        )); 
        $this->endWidget(); 
        ?> 

    <?php 

    Yii::app()->clientScript->registerScript('view-location-ajax', " 


    $('.exb-location').click(function(){ 
     url=$(this).attr('href'); 
     $.ajax({ 
     type: 'post', 
     url: url, 
     success: function(result){ 
      $('#location-dialog').html(result).dialog('open'); 
      $('#draggable').draggable(); 
      return false; 
     } 
    }); 
     return false; 
    }); 


    "); 
    ?> 

视图按钮操作正常,并且在打开CJuiModel点击但是当我在CGridView中添加一个新的位置时。 点击查看按钮我的CJuiModel不打开和页面重定向到Url.Why我的jQuery更新失败更新CGridView。帮助.. '上',而不是直接的事件使用JQuery

+0

你必须检查发送的数据类型,如发布或得到可能是这是冲突。 –

+0

类型:在我ClientScript –

+0

已经提到做它一赠类型超出既有可能是这种解决冲突 –

回答

0

更改AJAX调用绑定:

此:

... 

$('.exb-location').click(function(){ 
... 

更改为:

... 

$('.exb-location').on('click', '.exb-location', function(){ 
... 

HTML元素被破坏和再生后CGridview刷新。在DOM加载之前,直接JQuery事件仅适用于现有元素。当他们被删除,或新的元素后来被添加,direct events don't work