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
Ms. Alexandra Block
1
May 9, 2007, 7:23:16 PM
Dr. Kip Batz Jr.
2
Feb 5, 1987, 6:05:33 PM
Jewell Leffler
3
Sep 21, 2017, 5:15:56 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
Reanna Medhurst IV
May 31, 1995, 12:11:27 PM
2
Mckenzie Dietrich
Sep 30, 1981, 7:28:02 AM
3
Cary Bradtke
Oct 28, 1992, 3:46:43 PM

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