1

Am using kartik dynagrid and i would like to setup a text that shows when the dataprovider returns empty

The grid

echo DynaGrid::widget([
            'columns' => $columns,
            'showPersonalize' => true,
         'emptyText'=>'Sorry all pr have pritems',///-----------------This is what i had set
            'options' => ['id' => 'assignsolic-grid'],
            'gridOptions' => [
                'options' => ['id' => 'grid'],
                'dataProvider' => $dataProvider,
                 'filterModel' => $searchModel,
                 'showPageSummary'=>false,
                'pager' => [
                    'firstPageLabel' => 'First',
                    'lastPageLabel' => 'Last',
                    'maxButtonCount' => 10,
                ],
                   'panel' => [
             'type' => GridView::TYPE_PRIMARY,
                       // 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i> </h3>',
                      'before'=>'<i>Select the Prs to assign solicitation and then click the Assign Solicitation button</i>',
                      'after' =>

        Html::button(' <i class=" glyphicon glyphicon-road "></i> Assign Solicitation ', ['value' => Url::to('assignsolc'),'class' => 'btn btn-danger', 'id' => 'assignsolic']),

                        'footer' => false
                    ],
                'toolbar' => [
                    ['content' => '{dynagridFilter}{dynagridSort}{dynagrid}'],
                    '{export}',
                    '{toggleData}'
                ],
                'pjax' => true,
                'bordered' => false,
                'striped' => true,
                'condensed' => true,
                'responsive' => true,
                'responsiveWrap' => false,
                'containerOptions'=>['style'=>'overflow:scroll'],
            ]
        ]) ;

This returs an error of Setting unknown property: kartik\dynagrid\DynaGrid::emptyText how can i set the empty text

Geoff
  • 6,277
  • 23
  • 87
  • 197

2 Answers2

1

You can define the value for null display directly in confi/main.php formatter component

'components' => [
   .......
        'formatter' => [
        'class' => 'yii\i18n\Formatter',
        'dateFormat' => 'dd.MM.yyyy',
        'decimalSeparator' => ',',
        'thousandSeparator' => ' ',
        'currencyCode' => 'EUR',
        'nullDisplay' => '',           // **** this param 
    ],
 ..... 

Otherwise if the widget don't provide a proper attribute you can use an anonymous function for value

  [
    'attribute' => 'your_attribute',
    'value' => function ($model) {
        if ( $model->your_attribute == NULL) {
            return  'Sorry all pr have pritems';
        } else {
            return $model->your_attribute;
       }
     },
  ],
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • I have several dynagrids and each dynagrid should have a different message – Geoff Aug 06 '16 at 11:54
  • What do you mean by reference for dynagrid – Geoff Aug 06 '16 at 12:02
  • Documentation .. .. tecnical reference .. .. i know only this http://demos.krajee.com/dynagrid and there are no info for emptyValue – ScaisEdge Aug 06 '16 at 12:04
  • Yes i have seen the documentation but they dont point on the null desplay setting the null display returns the error Setting unknown property: kartik\dynagrid\DynaGrid::nullDisplay i have also included formatter in the components – Geoff Aug 06 '16 at 12:06
  • I would like the null message to be displayed in the content area where the data comes in and also probably not display the grid headers(colums) if the dataProvider is empty – Geoff Aug 06 '16 at 12:12
  • Currently when the dataProvider is empty it returns No results found. – Geoff Aug 06 '16 at 12:12
  • I have update an answer with a suggestion .. but i'm evaluating other solution too ... take a lool and let me know .. – ScaisEdge Aug 06 '16 at 12:15
  • I have check the doc .. at the moment the only way seems is the anonymous function in value attribute – ScaisEdge Aug 06 '16 at 12:22
  • Thanks for that i have got an idea from it since am using $dataProvider i just have to check if it is empty by if ($dataProvider->totalCount > 0) { then add my message. Ill ,mark your ans as correct – Geoff Aug 06 '16 at 12:28
  • @GEOFFREYMWANGI thank .. for this you can also use an infnull(your_column) in select from database – ScaisEdge Aug 06 '16 at 12:30
  • i also had an earlier question on wbranca extension in yii2 failing to update kindly checkout http://stackoverflow.com/questions/38768439/error-in-wbranca-dynagrid-update – Geoff Aug 06 '16 at 12:54
  • Could you please check a question i have posted on http://stackoverflow.com/questions/38853443/changing-yii2-password-by-checking-the-current-password-with-the-entered-passwor – Geoff Aug 09 '16 at 14:51
  • @GEOFFREYMWANGI .. Thank you for the confidence but unfortunately am not an expert in this – ScaisEdge Aug 09 '16 at 15:04
0

Since am using $dataProvider i found out that i just have to check if the dataProvider is empty by

if (!$dataProvider->totalCount > 0) { pass in message to display }
 else{?>

  SHOW THE GRID HERE

 <?php
  }
  ?>

   ?>
Geoff
  • 6,277
  • 23
  • 87
  • 197