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
Ines Fahey
1
Mar 4, 1998, 9:44:17 AM
Fern Cruickshank
2
Sep 12, 2009, 5:04:54 AM
Madaline Fahey
3
May 21, 1984, 6:33:37 AM

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
Elinor Rogahn
Nov 29, 1974, 1:39:59 PM
2
Amie Schimmel
May 28, 2009, 9:55:10 AM
3
Monte Witting
Jul 27, 1996, 7:40:55 PM

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