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
Ashly Sporer
1
Aug 6, 1971, 2:44:16 AM
Hattie Bernhard
2
Dec 9, 1971, 12:25:03 AM
Lucienne Smitham
3
Jul 30, 2009, 8:36:55 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
Gonzalo Rodriguez
Oct 13, 1994, 4:59:15 PM
2
Shemar Schneider
Apr 2, 1972, 6:42:04 AM
3
Miss Brooke Schoen II
Dec 18, 1975, 10:57:14 PM

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