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
Everette Bruen
1
May 14, 1993, 3:34:02 PM
Aglae Fritsch
2
Oct 17, 1989, 9:35:56 PM
Jean Konopelski Jr.
3
Oct 13, 1981, 8:16:48 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
Laisha Torp
Sep 4, 1981, 3:40:18 AM
2
Heidi Kuhic III
Nov 22, 1976, 3:55:28 PM
3
Narciso Schroeder
May 21, 1977, 5:50:04 PM

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