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
Kurtis Runolfsdottir
1
Feb 28, 1984, 6:32:22 AM
Megane Fadel
2
Aug 26, 1978, 2:43:35 PM
Dorothea Breitenberg
3
Aug 31, 1997, 10:11:01 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
Benton Grady
May 17, 2018, 6:07:56 AM
2
Chet Borer
Jun 27, 1984, 7:33:24 PM
3
Petra Schultz
Aug 23, 2009, 7:40:46 AM

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