Yii2 Components - Data tables

Data tables

DataTable is inherited from yii\grid\GridView. It is used to display data using MDC data table.
vip9008\MDC\components\DataTable

Usage

A basic usage looks like the following:

<?php
echo DataTable::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'name',
        'id',
        'created_at:datetime',
    ],
]);
?>

The above code will render a data table like the following:

Name ID Created at
Franco Ernser
1
Nov 8, 2009, 2:28:20 PM
Alicia Mann
2
Feb 15, 1977, 7:51:53 PM
Marilou Erdman MD
3
Jul 7, 2001, 2:03:29 PM

Customization options

Data table can be further customized by adding a header and action buttons.

<?php
echo DataTable::widget([
    'dataProvider' => $dataProvider,
    [
        'title' => 'Customers list',
        // Alternative header title configuration
        // 'title' => [
        //     'content' => 'Customers list',
        //     'options' => [...], HTML attributes for header title
        // ],
        'actions' => [
            '<button class="material-icon">filter_list</button>',
            '<button class="material-icon">more_vert</button>',
        ],
        // 'options' => [...], HTML attributes for table header container
    ],
    'columns' => [
        'id',
        'name',
        'created_at:datetime',
    ],
]);
?>
Customers list
ID Name Created at
1
Louvenia Hagenes DVM
Nov 11, 1982, 7:44:12 AM
2
Bettye Goyette III
Nov 18, 2011, 6:09:06 AM
3
Kaitlyn Witting
May 8, 2021, 4:17:27 PM

Other options are inherited from the parent class. see yii\grid\GridView.