kartik-v/yii2-grid toolbar not showing up

Dear all,

I’ve been using the yii2-grid widget from Kartik and it works great so far. The only issue I have is that the toolbar does not show up. I’ve tried different configuration options, nothing seems to work. This is my code:




<?php


use yii\helpers\Html;

use kartik\grid\GridView;




/* @var $this yii\web\View */

/* @var $searchModel app\models\UsertypeSearch */

/* @var $dataProvider yii\data\ActiveDataProvider */


$this->title = 'Usertypes';

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="usertype-index">


    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


    <p>

        <?= Html::a('Create Usertype', ['create'], ['class' => 'btn btn-success']) ?>

    </p>




    <?php

    $gridColumns = [

        //['class' => 'kartik\grid\SerialColumn'],

        [

            'class' => 'kartik\grid\DataColumn',

            'attribute' => 'name',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\BooleanColumn',

            'attribute' => 'can_create_booking',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\BooleanColumn',

            'attribute' => 'can_see_billing',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\BooleanColumn',

            'attribute' => 'can_create_user',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\BooleanColumn',

            'attribute' => 'can_create_instrument',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\BooleanColumn',

            'attribute' => 'can_create_job',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\BooleanColumn',

            'attribute' => 'can_create_supply',

            'vAlign' => 'middle',

        ],

        [

            'class' => 'kartik\grid\ActionColumn',

            'dropdown' => false,

            'vAlign' => 'middle',

        ],

        ['class' => 'kartik\grid\CheckboxColumn']

    ];


    echo GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => $gridColumns,

        'responsive' => true,

        'hover' => true,

        'floatHeader' => true,

        'floatHeaderOptions' => ['scrollingTop' => '50'],

        'showPageSummary' => false,

        'panel' => [

            'type' => GridView::TYPE_PRIMARY,

            'heading' => 'User Types',

        ],

        'export' => [

            'fontAwesome' => true

        ],

        'toolbar' => ['{export}'],

    ]);

    ?>




</div>




Any idea why the toolbar is not showing up?

Its the panel before setting which you did not provide that is causing this. By default the toolbar is embedded in the before part of the panel as per default template settings (unless you change them). Check the docs. It would have worked if you had set some value (e.g. blank space) for panel[‘before’]. The before and after part of the panel is not displayed until there was a value provided (in case someone wants to hide these sections).

However, with release v2.4.0 I have updated a fix, to always show before and after sections. One can set before and after to boolean false, if one wants to hide these sections.

To cut the long story short - please upgrade to latest release - it should work with your current settings. You can post issues on the github project page as well for faster response.

Hi Kartik,

thanks, I added ‘before’ => ’ ’ to the properties and it works now. I’m actually using 2.4.0 (at least that’s what the CHANGE.md file in the yii2-grid directory says.

Yes it should work. You can still run a composer update to get the latest release - because the v2.4.0 release is rebased and overwritten with other commits. With the latest update you do not need to set the before property to a blank space if you want to display it.

Note that if you set before to a valid value (could be any html markup) - then this will be displayed in addition to the toolbar - and will be floated left.