I have following widget in my yii2 application
<?= DateRangePicker::widget([
'model'=>$model,
'attribute' => 'fact_close_date_range',
'options'=>[
'placeholder'=>'Фактическая дата закрытия займа',
'class'=> 'ui input',
'id'=> 'fact_close_date_range'
],
'useWithAddon'=>false,
'convertFormat'=>true,
'presetDropdown'=>false,
'hideInput'=>false,
'pluginOptions'=>[
'opens' => 'right',
'locale'=>[
'format' => 'Y-m-d'
],
],
]);
?>
but on initial load what I am getting is input where two dates is set for today. For example 17.03.2021 - 17.03.2021, and should be my placeholder Фактическая дата закрытия займа like so. Documentation of kartik doesn't describe such things
try this :
<?= DateRangePicker::widget([
'name'=>'date_range_2',
'presetDropdown'=>true,
'convertFormat'=>true,
'value' => $model->date_range,
// 'includeMonthsFilter'=>true,
'pluginOptions'=> ['locale' => ['format' => 'Y-m-d']],
'options' => ['id'=> 'tgl-search', 'class' => 'invoice-search','placeholder' => 'Select range...']
]);
Related
how can I set width of column of gridview in view yii2,
reference link as below,
try this,
<?=
GridView::widget([
'model' => $model,
'options' => ['style' => 'width:80%'],
'attributes' => [
'id',
],
])
?>
To set width of one column individually something like the following:
[
'attribute' => 'attribute_name',
'headerOptions' => ['style' => 'width:20%'],
],
For all columns try:
[
'class' => 'yii\grid\SerialColumn',
'contentOptions' => ['style' => 'width:100px;'],
],
In Yii2 we have GridView like this:
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'layout' => "{items}\n{summary}\n{pager}",
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
'id',
'size',
'program' => [
'label' => 'Program',
'value' => function($data)
{
return Html::a($data->program, ($data->program), ['target' => '_blank']);
},
'format' => 'raw',
],
'version',
'platform',
'license',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Is it possible to do to hide/show column, if we click, for example on button "Hide platform", then for show "Show platform", or maybe checkbox.
I cannot understand how to do this, help me please
You can do something like this:
- Name the column you want to handle, e.g. an ID
[
'class' => 'yii\grid\SerialColumn',
'options' => [ 'id' => 'serial-column' ],
'width' => '1%',
'vAlign' => 'middle',
'hAlign' => 'right',
]
Then you modify css to have that column disappeared at the beginning
#serial-column {display: none}
Then you apply js for a checkbox to make it appear:
jQuery('#some-chkbox').click(function(){
jQuery('#serial-column').toggle();
})
Yes, you can hide and show column conditionally using "Visible" Attribute.
[
'attribute' => 'email',
'label' => 'Email',
'visible' => ($_GET['type']) == 'b') ? true : false,
],
I believe this is what you are looking for.
In short - you can add custom links and script to toggle columns of the gridview table.
I want a Datepicker inline with multidate enabled.
It is rendered correctly but returns only the last selected date.
Return value: '12.11.2016'
If I set 'type' to TYPE_INPUT everything is working fine.
Expected return Value: '23.11.2016, 24.11.2016, 18.11.2016, 12.11.2016'
<?= $form->field($model, 'dateString')->widget(DatePicker::className(), [
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'multidate' => true,
],
]);
?>
I'm using "kartik-v/yii2-widget-datepicker": "#dev" and the model is a ActiveRecord Model.
Seems to have been fixed with this commit: https://github.com/kartik-v/yii2-widget-datepicker/commit/39e0e71277d0f115341e118a2b879a0dfcbd01c3
This will solve the problem
echo $form->field($model, 'date_time')->widget(DatePicker::classname(), [
'options' => [
'value' => "Jul-11-2020,Jul-14-2021,Jul-12-2020",
'class' => "col-md-12 form-control picker"
],
'readonly' => false,
'language' => 'en',
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'format' => 'M-dd-yyyy',
'todayHighlight' => true,
'multidate' => true,
],
]);
I have gone through this:
http://www.yiiframework.com/extension/yii-barcode-generator-8-types/
https://github.com/Vilochane/Yii-Barcode-Generator
http://www.yiiframework.com/extension/yii2-barcode-generator-8-types/
But doesn't get it work. My gridView:
<?= GridView::widget([
'dataProvider' => new yii\data\ActiveDataProvider(['query' => $model->getLibBookMasters()]),
'summary' => '',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'lbm_book_no',
[
'attribute' => 'lbm_barcode_no',
//'type' => 'raw',
'value'=> function($model){
return \barcode\barcode\BarcodeGenerator::widget(
[
'elementId' => 'lbm_barcode_no',
'value'=> 'lbm_barcode_no',
'type'=>'ean13',
]);},
],
],
]); ?>
I need to pass elementId that do the trick but doesn't found it.
I just installed Barcode Generator and don't know how to play around with.
You need to pass different elementIds. As your code is currently your are passing the literal 'lbm_barcode_no' instead of the value of the lbm_barcode_no attribute of your models. In addition, you have to create the divs where the barcode is to be shown and set the format of the column to raw or html:
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'lbm_book_no',
[
'attribute' => 'lbm_barcode_no',
'format' => 'raw',
'value'=> function($model){
return yii\helpers\Html::tag('div', '', ['id' => 'barcode-'.$model->lbm_barcode_no]).
\barcode\barcode\BarcodeGenerator::widget([
'elementId' => 'barcode-'.$model->lbm_barcode_no,
'value'=> $model->lbm_barcode_no,
'type'=>'ean13',
]);
},
],
],
I prefixed the tags with barcode- to avoid collisions (you never know).
In Yii2 I want one of my input field to be autocomplete when user starts to type.Below is my code which uses Jui Autocomplete.
<?php
$items= ArrayHelper::map(Company::find()->all(), 'c_id', 'name');
echo AutoComplete::widget([
'model' => $model,
'attribute' => 'company',
'clientOptions' => [
'source' => $items,
],
]);?>
This is not working.When i printed my array, i got like
Array ( [1] => abc [2] => xyz [4] => pqr )
I got it working when i manually set like
$items=['abc','xyz','pqr'];
The reason may be my c_id's are not ordered?But i want to get the c_id value to be submitted!Any idea how to fix this?
This can be solved with the help of a hidden field input.Hope this will help somebody!
<?php
use yii\web\JsExpression;
$data = Company::find()
->select(['name as value', 'name as label','c_id as id'])
->asArray()
->all();
echo AutoComplete::widget([
'name' => 'Company',
'id' => 'ddd',
'clientOptions' => [
'source' => $data,
'autoFill'=>true,
'minLength'=>'4',
'select' => new JsExpression("function( event, ui ) {
$('#user-company').val(ui.item.id);
}")
],
]);
?>
<?= Html::activeHiddenInput($model, 'company')?>
Autocomplete just helps you fill the field with required value.
If you need to submit c_id look to dropdownList or Select2 plugin.
Check this http://demos.krajee.com/widget-details/select2 yii2 widget for ideas.
Here example code:
<?php
use kartik\widgets\Select2;
use app\models\Modelname;
$model = new Modelname;
$data = ['qwe1'=>'color1','key2'=>'color3']
?>
<?= Html::beginForm() ?>
<?= Select2::widget([
'model' => $model,
'attribute' => 'color',
'data' => array_merge(["" => ""], $data),
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
]); ?>
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
<?= Html::endForm() ?>
It also supports ajax loaded data: http://demos.krajee.com/widget-details/select2#ajax
I wanted to use the Jui Autocomplete so that when I click or focus on autocomplete textbox, it should display options.
I wrote following code and it seems to be working
$floorOptionsArray = ['Basement', 'Ground Floor', 'First floor', 'Second floor', 'Third floor'];
// $floorOptionsArray = array_combine($floorOptionsArray, $floorOptionsArray);
$model = new Customer();
echo $form->field($model, 'floor')
->widget(\yii\jui\AutoComplete::classname(), [
'value' => (!empty($model->floor) ? $model->floor : ''),
'clientOptions' => [
'source' => $floorOptionsArray,
'enabled' => true,
'minLength' => 0
],
'options' =>
[
'placeholder' => 'Floor',
'class' => 'form-control autocomplete-input-bg-arrow ',
'onclick' => "(function ( ) {
$( '#customer-floor' ).autocomplete( 'search', '' );
})();",
'onfocus' => "(function ( ) {
$( '#customer-floor' ).autocomplete( 'search', '' );
})();",
],
])->label(true);