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
Amely Bednar
1
May 1, 2013 8:04:27 AM
Jacinthe Heidenreich
2
Jan 12, 2013 11:35:50 PM
Rae Pacocha
3
Apr 2, 2010 8:51:14 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
Prof. Dorthy Ward IV
Sep 12, 2001 2:55:40 PM
2
Dianna Willms
Feb 4, 1994 2:58:10 PM
3
Lazaro Ratke
Apr 29, 2016 7:33:34 PM

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