2012-09-07 28 views
3
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'message-grid', 
    //'selectionChanged'=>'js:function(id){location.href = "'.$this->createUrl('view').'/id/"+$.fn.yiiGridView.getSelection(id);}', 
    'selectionChanged'=>'function(id){location.href = "'.$this->createUrl('view').'&id="+$.fn.yiiGridView.getSelection(id)+"&f=s";}', 
//'dataProvider'=>$model->sentitem(), 
    'dataProvider'=>$model->search(),  
'filter'=>$model, 
    'columns'=>array(
      array(  
         'class'=>'CCheckBoxColumn', 
         'id'=>'chk', 
         'selectableRows'=>'2', 
         //'htmlOptions'=>array('width'=>'40px'), 

      ), 

), ));如何通過雙擊訪問Yii Cgridview中選定行的ID?

我已經寫了通過選擇單次點擊的代碼改變我嘗試通過jQuery的dbclick功能的ID,我不知道如何獲取使用選擇的ID在dbclick改變

回答

0

試試這個:

$('#message-grid tbody tr').live('dbclick', function() { 
    var id = $.fn.yiiGridView.getKey(
     'message-grid', 
     $(this).prevAll().length 
    ); 
}); 
+0

感謝mashingan。 – AravindRaj

+0

有沒有錯誤?嘗試在dbclick處理程序中使用console.log'id',它返回什麼? –

+0

請注意,從$ Yii 1.1.9開始,'$ .fn.yiiGridView.getKey'標記爲**棄用**。 – trejder

0

下面的代碼將加載項目的視圖頁面。 (url => itemcontroller/view/id/+ selectedId)

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'id-grid', 
    'dataProvider'=>$dataProvider, 
    'filter'=>$model, 

    'selectableRows'=>1, 
    'selectionChanged'=>'function(id){ location.href = "'.$this->createUrl('view').'/id/"+$.fn.yiiGridView.getSelection(id);}',