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
Miss Isobel Abernathy I
1
Aug 15, 1989, 12:19:00 AM
Jacinto Schuppe
2
Jan 14, 1992, 5:40:00 PM
Kevin Beer
3
Jan 18, 1977, 12:52:40 AM

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
Dr. Maximillia Funk
May 27, 1997, 10:59:46 AM
2
Coralie Will
Dec 13, 2003, 4:39:58 AM
3
Gussie Cartwright
Feb 10, 1974, 4:48:59 PM

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