2013-12-09 20 views
1

在基於YII的項目中,我有一個cgridview。要求是將整行或每列值作爲鏈接並單擊行中的任何鏈接將觸發ajax調用。我從這裏試過 How to display rows of CGridView as a linkYii - CGridView行/列值作爲鏈接並在點擊時調用ajax函數

但問題是,如果我把整行作爲可點擊它需要我查看操作。

如果我將一行中的單個列值作爲鏈接並調用ajax函數,我會得到以下錯誤。

Property "CDataColumn.options" is not defined. 

我需要在製作整排可點擊幫助,並呼籲一個Ajax功能或各行值調用上點擊一個Ajax功能。

任何幫助或正確的方向指導非常感謝。 http://www.yiiframework.com/doc/api/1.1/CGridColumn#htmlOptions-detail

您必須使用「htmlOptions」如果你婉設置選項:如警予文檔中說

//code for making trading name column in cgridview as clickable and call ajax 

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'customer-grid', 
    'dataProvider'=>$model->search(), 
    'filter'=>$model, 
    'columns'=>array(
     'id', 
     array(
        'name' => 'trading_name', 
        'value' => 'CHtml::link($data->trading_name, Yii::app() 
        ->createUrl("customer/view/",array("id"=>$data->primaryKey)))', 
        'type' => 'raw', 
        'options' => array('ajax' => array('type' => 'get', 'url'=>'js:$(this).attr("href")', 
        'success' => 'js:function(data) { 
         $("#tab1").html(data);') 
        ), 
       ), 
     'email',  
     'site_code', 

     array(
      'class'=>'CButtonColumn', 
     ), 

回答

1

一些麻煩,我是能夠使後cgridview的一行鏈接,並點擊每行調用一個AJAX函數。以下是代碼。可能對某人有幫助。

selectionChanged訣竅。點擊任何行可調用ajax函數,並在網格下方顯示每個客戶的信息div。

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'customer-grid', 
'dataProvider'=>$model->search(), 
'selectionChanged'=>'js:function(id){ 
n = $.fn.yiiGridView.getSelection(id); 
if (n>0){ 
    $.ajax({ 
      url: "'.Yii::app()->urlManager->createUrl('customer/view/').'", 
      type: "GET", 
      data: {"id": parseInt(n)}, 
      dataType: "html", 
      success: function(data) { 
      $("#customer-div").html(data); 
     } 
     });', 

    'filter'=>$model, 
    'columns'=>array(
    'id', 
    array(
       'name' => 'trading_name', 
       'value' => 'CHtml::link($data->trading_name, Yii::app() 
       ->createUrl("customer/view/",array("id"=>$data->primaryKey)))', 
       'type' => 'raw', 
       'options' => array('ajax' => array('type' => 'get', 'url'=>'js:$(this).attr("href")', 
       'success' => 'js:function(data) { 
        $("#tab1").html(data);') 
       ), 
      ), 
    'email',  
    'site_code', 

    array(
     'class'=>'CButtonColumn', 
    ), 
相關問題