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
Ms. Pauline Runolfsdottir DDS
1
Mar 27, 1977, 12:20:28 AM
Alyce Dibbert
2
Nov 18, 1994, 5:50:17 AM
Blaise Weber II
3
May 14, 1983, 5:59:26 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
Mr. Robin Tremblay Jr.
Feb 4, 1978, 10:51:47 PM
2
Mrs. Maci Torphy
Oct 19, 1975, 6:02:07 PM
3
Shannon Huels
Aug 29, 1989, 1:43:53 AM

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