2014-03-31 74 views

回答

3

添加'options' => array('target'=>'_new')到CButtonColumn配置陣列中CGridView

array(
    'class'=>'zii.widgets.grid.CButtonColumn', 
    'template' => '{view}', 
    'buttons'=>array(
     'view' => array(
      'url' => '', // view url 
      'options' => array('target' => '_new'), 
     ), 
    ), 
), 
+0

謝謝安德烈非常好 – maryam

0

您可以通過使用 '選擇' 屬性提供的HTML屬性。

<?php 
    $this->widget('zii.widgets.grid.CGridView', array(
     'dataProvider' => $dataProvider, 
     'columns' => array(
      'table_field_1', 
      'table_field_2', 
      'table_field_3', 
      array(
       'class' => 'CButtonColumn', 
       /* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */ 
       //'template' => '{view} {update} {delete}', 
       'buttons' => array(
        'view' => array(
         'options' => array('class' => 'newWindow'), 
        ), 
       ), 
      ), 
     ), 
    )); 
    ?> 

但是,打開一個新窗口依賴於瀏覽器。與target="_blank"target="_new"鏈接將在Mozilla的新標籤中打開,但在IE中您將獲得新窗口。所以用戶javascript來生成新窗口。

<?php 
    $this->widget('zii.widgets.grid.CGridView', array(
     'dataProvider' => $dataProvider, 
     'columns' => array(
      'table_field_1', 
      'table_field_2', 
      'table_field_3', 
      array(
       'class' => 'CButtonColumn', 
       /* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */ 
       //'template' => '{view} {update} {delete}', 
       'buttons' => array(
        'view' => array(
         'options' => array('class' => 'newWindow'), 
        ), 
       ), 
      ), 
     ), 
    )); 
    ?> 

保持這個jQuery在你的js文件

<script> 
     $(document).ready(function() 
     { 
      $(".newWindow").click(function(e) 
      { 
       e.preventDefault(); 
       var url=$(this).attr('href'); 
       window.open(url, "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=100, left=100, width=1020, height=500"); 
      }); 
     }); 
    </script> 
0

您可以使用此

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider, 
    'columns' => array(
     'table_field_1', 
     'table_field_2', 
     'table_field_3', 
     array(
      'class' => 'CButtonColumn', 
      /* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */ 
      //'template' => '{view} {update} {delete}', 
      'buttons' => array(
       'view' => array(
        'options' => array('target' => '_blank'), 
       ), 
      ), 
     ), 
    ), 
)); 
?> 
相關問題