0

Using Kartik Gridview, I have the following ExpandRowColumn in my view (Kartik Gridview) where I have enabled the rows in the grid to be clicked and expanded (to show related detail record) with the enableRowClick option and would like to hide the entire expand/collapse icon row and use only the row click ability. I have tried setting the 'disabled' option but that just makes the ExpandRowColumn disabled altogether.

[
  'class' => 'kartik\grid\ExpandRowColumn',
  'width' => '50px',
  'value' => function ($model, $key, $index, $column) {
       return GridView::ROW_COLLAPSED;
   },
   'detail' => function ($model, $key, $index, $column) {
       return Yii::$app->controller->renderPartial('_example', ['model' => $model]);
   },
   'headerOptions' => ['class' => 'kartik-sheet-style'],
   'expandOneOnly' => true,
   'enableRowClick' => true,
],
Naing Lin Aung
  • 3,373
  • 4
  • 31
  • 48
Mark C.
  • 576
  • 1
  • 8
  • 23

3 Answers3

1

I hacked the widget source, have managed to make the icons go away but the column remains. Plus of course it should come back with I update the widget :-) !

in \vendor\kartik-v\yii2-grid\ExpandRowColumn.php

public function init()
{
    parent::init();
    if (empty($this->detail) && empty($this->detailUrl)) {
        throw new InvalidConfigException("Either the 'detail' or 'detailUrl' must be entered");
    }
    $this->format = 'raw';
//    $this->expandIcon = $this->getIcon('expand');
//    $this->collapseIcon = $this->getIcon('collapse');
kevin
  • 11
  • 1
  • Thanks. I think I need a more long-term solution that makes the column disappear though your proposed solution is appreciated. – Mark C. Apr 27 '17 at 18:28
0
[
            'class' => 'kartik\grid\ExpandRowColumn',
            'width' => '50px',
            'value' => function ($model, $key, $index, $column) {
                return GridView::ROW_COLLAPSED;
            },
            'detail' => function ($model, $key, $index, $column) {
                return Yii::$app->controller->renderPartial('_expand', ['model' => $model]);
            },
            'headerOptions' => ['class' => 'kartik-sheet-style'],
            'expandOneOnly' => true,
            'expandIcon' => '<span class="glyphicon glyphicon-triangle-right"></span>',
            'collapseIcon' => '<span class="glyphicon glyphicon-triangle-bottom"></span>',
        ],
  • Why not try expanding on your answer rather than just posting code!! Elaborate more on why this answer will benefit the OP! – Kebab Programmer Apr 09 '19 at 15:08
  • 1
    I don't think this will make the actual row disappear will it? I'm not using Yii2 too much these days and don't have a quick way to test, but I think your code is just making the icon disappear correct? My original question was how to make the actual icon ROW disappear. – Mark C. Apr 26 '19 at 03:28
0

I'm also facing the same issue. At last, I just succeeded by placing empty string. My workaround will be as follows

[
  'class' => 'kartik\grid\ExpandRowColumn',
  'width' => '50px',
  'value' => function ($model, $key, $index, $column) {
      return GridView::ROW_COLLAPSED;
   },
  'detail' => function ($model, $key, $index, $column) {
      return Yii::$app->controller->renderPartial('_expand', ['model' => $model]);
   },
  'headerOptions' => ['class' => 'kartik-sheet-style'],
  'expandOneOnly' => true,
  'expandIcon' => '',
  'collapseIcon' => '',
],
Naing Lin Aung
  • 3,373
  • 4
  • 31
  • 48