Yii2 Components - Data tables
RTL direction
Dark theme

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
Dianna Hartmann
1
Oct 27, 2004 5:10:43 PM
Mrs. Stephanie Bradtke MD
2
Aug 28, 1975 8:51:23 AM
Miss Augustine Runolfsdottir
3
Mar 19, 1973 10:49:15 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
Cleo Berge Sr.
Mar 20, 1982 6:33:12 AM
2
Katheryn Pfeffer
Jul 14, 2011 3:35:25 AM
3
Glenda Armstrong
Aug 14, 1995 5:48:11 PM

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