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
Dr. Theodora Hahn
1
Jan 28, 1997, 2:24:53 PM
Gerardo Kuvalis
2
Mar 10, 1981, 1:40:31 PM
Leanna Maggio
3
Sep 23, 1977, 4:47:39 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
Melba Kuhn
Dec 2, 1988, 4:10:03 PM
2
Jack Hane
Mar 8, 1979, 5:35:53 AM
3
Prof. Stewart Hayes
Dec 3, 1973, 12:29:15 PM

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