0

I already search and try every forum and example.

I am using the Kartik\DetailViwew in Yii2 and I can´t manage to put a single custom button in the buttons1 option.

The code I am working on:

    echo DetailView::widget([
        'model' => $model,
        'attributes' => $attributes,
        'mode'=>Yii::$app->request->get('edit')=='t' ? DetailView::MODE_EDIT : DetailView::MODE_VIEW,
            'panel'=>[
            'heading'=>$this->title,
            'type'=>DetailView::TYPE_INFO,
            ],
        'buttons1' => '{update}',
        'bordered' => 'true',
        'striped' => $striped,
        'condensed' => $condensed,
        'responsive' => $responsive,
        'hover' => $hover,
        'hAlign'=>$hAlign,
        'vAlign'=>$vAlign,
        'fadeDelay'=>$fadeDelay,
        'deleteOptions'=>[ // your ajax delete parameters
          'params' => ['id' => $model->p_id, 'custom_param' => true],
          'url'=>['delete', 'id' => $model->p_id],
        ]

    ]);

In the

        'buttons1' => '{update}',

According to the example http://demos.krajee.com/detail-view, there is a way to customize. But there is no example. And the documentation not explain how to do this.

Can anyone help?

2 Answers2

0

After research and some tryings, I did it by this way, you have to enable the edit mode (to show buttons), and modify the defatul template ({buttons}{title}), as this template is replaced if the template exists in vender grideview constants, just inject your code to add any button u want. Is not the rigth solution, but is a workaround that works well

<?php
$button1 = Html::a('<i class="glyphicon glyphicon-trash"></i>', Url::to(['delete', 'id' => $model->id]), [
                   'title' => 'Eliminar',
                   'class' => 'pull-right detail-button',
                   'data' => [
                       'confirm' => '¿Realmente deseas eliminar este elemento?',            
                       'method' => 'post',
                   ]
           ]);
$button2 = Html::a('<i class="glyphicon glyphicon-pencil"></i>', Url::to(['actualizar', 'id' => $model->id]), [
                   'title' => 'Actualizar',
                   'class' => 'pull-right detail-button',
           ]);
?>
<?=
DetailView::widget([
                   'model' => $model,
                   'hover' => true,
                   'hideAlerts' => true,
                   'enableEditMode' => true,
                   'mode' => DetailView::MODE_VIEW,
                   'hAlign' => 'left',
                   'panel' => [
                       'heading' => '&nbsp',
                       'type' => DetailView::TYPE_DEFAULT,
                       'headingOptions' => [
                           'template' => "$button1 $button2 {title}"
                       ]
                   ],
                   'attributes' => [
                       'id',
                       'identificacion',
                       'nombre',    
                   ],
         ])
?>
Leonardo Sapuy
  • 2,600
  • 2
  • 23
  • 30
0

Try it like this:

'buttons1' => Html::a('<i class="glyphicon glyphicon-trash"></i>', Url::to(['delete', 'id' => $model->id]), [
                   'title' => 'Eliminar',
                   'class' => 'pull-right detail-button',
                   'data' => [
                       'confirm' => '¿Realmente deseas eliminar este elemento?',            
                       'method' => 'post',
                   ]
           ]),

If you have more than one button, try it like this:

$button1 = Html::a('<i class="glyphicon glyphicon-trash"></i>', Url::to(['delete', 'id' => $model->id]), [
                   'title' => 'Eliminar',
                   'class' => 'pull-right detail-button',
                   'data' => [
                       'confirm' => '¿Realmente deseas eliminar este elemento?',            
                       'method' => 'post',
                   ]
           ]);
$button2 = Html::a('<i class="glyphicon glyphicon-pencil"></i>', Url::to(['actualizar', 'id' => $model->id]), [
                   'title' => 'Actualizar',
                   'class' => 'pull-right detail-button',
           ]);


    'buttons1' => "{$button1} {$button2}",
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83