Yii gridview onclick rows to expand and show a detailed view below the row in the grid

how to show a grid as a grid in GRIDVIEW WITH ROW EXPAND AND COLLAPSE the grid should show normal data when viewing a row that should show the details of the corresponding row. Help handle this ... my conclusion should be similar to

MY GRID SHOULD BE LIKE THIS

And when I click on the row, it should open and give detailed information (the image will show the table, but I do not need to display a detailed view in it. enter image description here

EDITED I forgot to add something that the grid will load from one model, and row data will be loaded from another model.

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

'columns'=>array(

    array(
        'name'  => 'Project',
        'value' => 'Project::model()->findByPk($data->Project)->proj_name',
   'filter'=>CHtml::listData(Project::model()->findall(),'proj_id','proj_name'),
        ),

    'isbn_no',
    'source_type',
array(
        'name'  => 'complexity',
        'value' => 'Complexity::model()->findByPk($data->complexity)->Complexity_Name',
                                                      'filter'=>CHtml::listData(Complexity::model()->findall(),'id','Complexity_Name'),
       'footer'=>'Total Page',
        ),
      array('class'=>'CButtonColumn',
     'template'=>'{detail}',
     'buttons'=>array(
      'detail'=>array(
            'label'=>'Show Details', 
                    'url'  =>'Yii::app()->createUrl("Process/View",   array("id"=>$data->book_id))',
                    'options'=>array('title'=>'Show details','class'=>'detailsLink'),
  'click'=>"$('#your-grid-book_id').on('click','.detailsLink',function(){
     var row=$(this).closest('tr');
      var url=$(this).attr('href');
   $.get(url,{},function(data){
  row.after(data.row);
     },'json');
     })",

            )
    ) 
)

),
    )); ?>  

i trided this, but the grid from the book model and the reference to the process model in the CButton column are not used

+3
2

:

GridView:

'columns'=>array
     (
            'ID',
            array
            (
                  'name'=>'...',
                  'htmlOptions'=>array('class'=>'plus','id'=>$data->id),
                  'value'=>'...',
            ),
            ...
     ),

js code:

$(".plus").click(function(){
var data = $(this).attr('id');
var url = ...ajax url...
jQuery.ajax({
                'type':'post',
                'data':data,
                'url':url,
                'cache':false,
                'success':function(html){
                                                var new_data = $("<div></div>").attr("class", "appended_data").html(html).attr("id",data);
                                                $(this).parent().append(new_data);
                                                $(this).removeClass('plus');
                                                $(this).addClass('minus');
                                        }
        }); 
});

ajax trs ( ). , .

+4

Rajats :

gridview:

array(
            'class' => 'ButtonColumn',
            'template' => '{view}{confirm}',
            'evaluateID' => true,
            'buttons' => array(
                'view' => array(
                    'icon' => 'info-sign white',
                    'url' => '#',
                    'options' => array(
                        'title' => Yii::t('app', 'view'),
                        'onclick' => 'javascript:toggleRow($(this).attr("id"))',
                        'class' => 'btn-primary',
                        'id' => '$data->id'
                    ),

, ButtonColumn, , : http://www.yiiframework.com/wiki/372/cbuttoncolumn-use-special-variable-data-for-the-id-in-the-options-of-a-button/

javascript:

function toggleRow(id) {
    if ($('#table'+id).length) {
        $('#table'+id).remove();
    } else {
        $.ajax({
            'type': 'post',
            'data': {
                "payment_id": id
            },
            'url': "<?php echo Yii::app()->createUrl('controller/action'); ?>",
            'success': function (html) {
                var new_data = $("<tr></tr>").attr("class", "btn-danger").html(html).attr("id", "table"+id);
                new_data.insertAfter($('#' + id).parent().parent());
            },
            'error': function (err) {
                console.log(err);
            }
        });
    }
}

, ajax, html:

public function actionControlleraction(){
    if (isset($_POST['payment_id'])) {
        $payment = Payment::model()->findByPk($_POST['payment_id']);
        $html = $payment->createHtmlTable();
        print_r($html);
    }
}

html .

0

All Articles