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
Mercedes Schoen
1
Oct 24, 2011 7:22:57 AM
Cameron Turner DDS
2
Mar 30, 1993 2:11:01 AM
Jaeden Runolfsdottir IV
3
Jun 17, 2010 6:47:24 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
Dr. Abigale Walker DVM
Nov 20, 2015 10:12:44 AM
2
Lucie O'Kon
Apr 30, 2006 10:04:10 AM
3
Lilly Crooks PhD
Jul 23, 2016 2:57:48 AM

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