Yii2: Add the ability to not render empty row in GridView when dataProvider does not have any data

Created on 8 Jan 2017  路  12Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

<?= \yii\grid\GridView::widget([
    'dataProvider' => new \yii\data\ArrayDataProvider([
        'allModels' => [],
    ]),
    'showHeader' => false,
    'emptyText' => false,
]) ?>

What is the expected result?

<table><tbody></tbody></table>

What do you get instead?

<table><tbody><tr><td colspan="0"><div class="empty"></div></td></tr></tbody></table>

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.10
| PHP version |5.6
| Operating system |xubuntu 16.04

ready for adoption enhancement

All 12 comments

Is it solve your problem?

<?= \yii\grid\GridView::widget([
    'dataProvider' => new \yii\data\ArrayDataProvider([
        'allModels' => [],
    ]),
       'showOnEmpty' => false,
    'emptyText' => '<table><tbody></tbody></table>',
]) ?>

I got <div class="empty"><table><tbody></tbody></table></div>
And the GridView::$layout has not been used for rendering.

Thank you for the idea, but the solution is more like a crutch.

Where do I want to use it

How would you solve it?

In this place I would like to add something like

if ($this->emptyText === false)
    return "<tbody>\n</tbody>";

or add an additional condition here if (empty($rows) && $this->emptyText !== false) {

Additional condition solution sounds good to me.

@dkhlystov would you like to submit a PR?

What do you mean? What is PR?

PR is a pull request.

We have a Git workflow for Yii 2 contributors, that will help you to do it for the first time

This is to complicated for me.

Then either core team or community will handle it later. Thanks for idea.

Was this page helpful?
0 / 5 - 0 ratings