How to render empty grid table in Yii?

Viewed 771

I am working on the Yii2 project. In this, on page load, I want to display an empty grid table. Data should get loaded to the Kartik GridView only after button click. I am able to display the grid view table with data on button click, but not able to display the empty grid table initially. To display data, I have added code as follows:

use kartik\grid\GridView;
<?=
        GridView::widget([
            'id' => 'crud-datatable',
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'pjax' => false,
            'floatHeader'=>true,
            'floatOverflowContainer'=>true,
        ])
        ?>

I was reading about renderEmpty() but don't know how to use this also I tried sending NULL as a dataprovider but was creating the issue. Is there any other GridView property that we can use to display an empty table initially?

1 Answers

To solve this, I have passed object of ArrayDataProvider as a value of dataProvider like,

$dataProvider = new \yii\data\ArrayDataProvider();
Related