, (*1)
Install
Either run, (*2)
php composer.phar require --prefer-dist brussens/yii2-datetimepicker-widget "*"
or add, (*3)
"brussens/yii2-datetimepicker-widget": "*"
to the require section of your composer.json
file., (*4)
Options
-
format - datetime format
-
clientOptions - options of plugin. See http://eonasdan.github.io/bootstrap-datetimepicker/#options
Base usage:
use brussens\datetimepicker\Widget as DateTimePicker;
echo $form->field($model, 'attribute')->widget(DateTimePicker::className());
Advanced usage
use brussens\datetimepicker\Widget as DateTimePicker;
echo $form->field($model, 'attribute')->widget(DateTimePicker::className(), [
'format'=>'DD-MM-YYYY HH:mm:ss',
'clientOptions' => [
'locale' => 'ru', //If you do not want to use auto-detection
'icons' => [
'time' => 'el-icon-time',
'date' => 'el-icon-calendar',
'up' => 'el-icon-chevron-up',
'down' => 'el-icon-chevron-down',
],
'useSeconds' => true,
'useCurrent' => true,
'sideBySide' => true
],
]);
Range usage (experimentally)
use yii\grid\GridView;
use brussens\datetimepicker\RangeWidget;
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $model,
'columns' => [
//... some columns
[
'filter' => RangeWidget::widget([
'model' => $model,
'attribute' => 'date_from',
'attributeTo' => 'date_to'
]),
'attribute' => 'created_at',
'format' => 'datetime',
],
['class' => 'yii\grid\ActionColumn'],
],
]);
Profit