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
Mrs. Erika Larkin
1
Jul 17, 2011 11:05:20 PM
Abigayle Considine
2
Jan 3, 2006 5:51:02 AM
Briana Swaniawski
3
Nov 4, 1985 10:57:24 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
Godfrey Dicki
Oct 13, 2008 5:56:41 AM
2
Prof. Stephan Stracke
Mar 7, 1993 5:51:51 PM
3
Prince Waelchi
Jul 5, 1981 3:16:59 PM

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