2013-12-19 52 views
1

如何從CGridView通過網格行ID在另一個CGridView篩選值對話框傳遞ID來CGridView

enter image description here

我查看代碼的形式兩重網格(見截圖),

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

    'columns'=>array(   
    array(
         'class' => 'CButtonColumn', 
         'template' => '{edit}{DocumentDelete}', 
         'buttons' => array(
          'DocumentDelete' => array(
          'imageUrl'=>Yii::app()->request->baseUrl.'/images/delete.png', 
          'url'=>'Yii::app()->createUrl("baseContact/DocumentDelete", array("id"=>$data->crm_document_id))', 

          ), 
          'edit' => array(
          'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png', 
          'url'=>'Yii::app()->createUrl("baseContact/edit", array("id"=>$data->crm_document_id))', 

          ), 
        ),), 
     'crm_document_id', 
     'name', 
     'doc_type', 
     'delivery_method', 
     'content_subject', 
     'content_body', 
     'is_active', 

    ), 

)); ?> 
打開

Popup Grid的查看代碼,

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'ManagedocumentAttach-grid', 
    'dataProvider'=>DocumentAttachmentModel::model()->search(), 
    //'filter'=>$model, 
    'columns'=>array(
    array(
     'name'=>'',    
     'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->crm_document_attachment_id,"id"=>"cid_".$data->crm_document_attachment_id))', 
     'type'=>'raw', 
     'htmlOptions'=>array('width'=>5), 
     //'visible'=>false, 
     ),  
     'crm_document_id', 
     'name', 
     'type', 

    ), 

)); ?> 

如何通過表格編輯行ID到Popup GridView?

+0

數據請將您CGridView執行代碼// openn彈出。 – Kai

+0

@ user714965添加了Cgridview實現代碼... – TMKS

回答

1

很明顯,您使用AJAX來獲取彈出窗口,所以我首先要確保編輯按鈕的ID與要打開的項目的ID相同。然後,你可以做以下的JS(使用jQuery)

$(".edit").on("click", function() { 
    var id = $(this).attr("id"); 
    $.ajax({ 
     type:"POST", 
     url: "controller/action/"+id; 
     success: function(data) { 
      //open dialog box and fill it with data 
     } 
}); 

您還可以添加ID數據,因此您可以用$_POST,而不是它是由函數定義的變量得到它。如果你在PHP文檔中編寫JS,你可以使用$this->createUrl,但這只是你喜歡的。

如果有了這個,你不能解決你的問題,那麼讓我們看看你現在是如何實現它的。

0

我不知道......但我有一種技術來做到這一點.... 如果我不得不做這樣的事情....

我將htmlOptions和我後給類將獲得這應該是一個id打開彈出值..

例如

<?php $this->widget('bootstrap.widgets.TbGridView', array(
      'dataProvider' => $dataProvider , 
      'type' => TbHtml::GRID_TYPE_BORDERED, 
      'template' => "{items}", 
      'columns' => array(
       array(
        'name' => 'vendor_configuration_id', 
        'header' => $dataProvider->model->getAttributelabel('vendor_configuration_id'), 
        'htmlOptions' => array('class'=>'idClass'), 

       ), 
       array(
        'name' => 'menu_type', 
        'header' => $dataProvider->model->getAttributelabel('menu_type'), 
        'htmlOptions' => array(), 
       ), 

?> 

現在的jQuery它

$('.idClass').on("click",function(){ 

var neededId = $(this).html(); 

alert(neededId);  

基於此ID或CAAL阿賈克斯以檢索在此基礎上

});