i am trying to set width and height on my phone in my gridview this is my code
[ 'attribute' => 'iduser.photo',
'format' => 'html',
'value'=> function($data) { return Html::img($data->imageurl,['id'=>'photo']); },
],
i have tried with this
[ 'attribute' => 'iduser.photo',
'format' => 'html',
'value'=> function($data) { return Html::img($data->imageurl,['image'=>'100']); },
],
but i cant put px or percent for that
where i put class for css or set style ?
ok i got answer for my answer question.
this is the code
[ 'attribute' => 'iduser.photo',
'format' => 'html',
'value'=> function($data) { return Html::img($data->imageurl,['id'=>'photo']); },
'contentOptions'=>['style'=>'max-width: 10px; max-height: 10px'],
],
thx google :p
Related
I've detail showed using Kartik Detail View. This widget has Edit inline function by clicking pencil icon button in top right side like this.
But then the table doesn't be editable :
And nothing happen, my data still the same, my update not success. It's possible to solve my problem? Thanks.
I have read the official guide and it looks identical:
https://demos.krajee.com/detail-view
This is my view code:
<?php echo DetailView::widget([
'model' => $modelAnagrafiche,
'responsive' => true,
'mode' => 'edit',
'enableEditMode' => true,
'buttons1' => '{update}',
'panel' => [
'type' => 'primary',
'heading' => 'Contratto' . ' : ' . $modelAnagrafiche >cognome_ragione_sociale . ' ' . $modelAnagrafiche->nome
],
'attributes' => [
[
'group'=>true,
'label'=>'Sezione Anagrafica',
'rowOptions'=>['class'=>'table-primary']
],
[
'columns' => [
[
'attribute' => 'cognome_ragione_sociale',
'displayOnly' => true,
'valueColOptions' => ['style' => 'width:30%']
],
[
'attribute' => 'nome',
'format' => 'raw',
'valueColOptions' => ['style' => 'width:30%'],
'displayOnly' => true,
'type' => DetailView::INPUT_TEXT,
],
],
],
[
'columns' => [
[
'attribute' => 'codice_fiscale',
'displayOnly' => true,
'valueColOptions' => ['style' => 'width:30%']
],
[
'attribute' => 'partita_iva',
'format' => 'raw',
'valueColOptions' => ['style' => 'width:30%'],
'displayOnly' => true
],
],
],
[
'columns' => [
[
'attribute' => 'tipo_documento',
'displayOnly' => true,
'valueColOptions' => ['style' => 'width:30%'],
'format' => 'raw',
'value' => $modelAnagrafiche->tipoDocumento,
],
[
'attribute' => 'numero_documento',
'format' => 'raw',
'valueColOptions' => ['style' => 'width:30%'],
'displayOnly' => true
],
],
],
[
'columns' => [
[
'attribute' => 'data_nascita',
'displayOnly' => true,
'format' => 'date',
'type' => DetailView::INPUT_DATE,
'widgetOptions' => [
'pluginOptions' => ['format' => 'yyyy-mm-dd']
],
],
[
'attribute' => 'id_provincia_nascita',
'displayOnly' => true,
'valueColOptions' => ['style' => 'width:30%'],
'format' => 'raw',
'value' => $modelAnagrafiche->provinciaNascitaNome,
'label' => 'Provincia Nascita'
],
],
],
[
'columns' => [
[
'attribute' => 'id_comune_nascita',
'displayOnly' => true,
'format' => 'raw',
'value' => $modelAnagrafiche->comuneNascitaNome,
'label' => 'Comune Nascita'
],
],
],
],
]);
?>
This is the action in my controller:
public function actionUpdateAnagrafica()
{
$post = Yii::$app->request->post();
if (empty($post['Anagrafiche']['id'])) {
throw new NotFoundHttpException('Non esiste nessuna anagrafica.');
}
$modelAnagrafiche = Anagrafiche::findOne($post['Anagrafiche']['id']);
if ($modelAnagrafiche->load($post) && $modelAnagrafiche->save()) {
return $this->redirect(['view', 'id' => $modelAnagrafiche->id]);
} else {
return $this->render('update-anagrafica', [
'modelAnagrafiche' => $modelAnagrafiche,
]);
}
}
You have to remove all the displayOnly attributes.
According to the official guide:
displayOnly: boolean|Closure, if the input is to be set to as display
only in edit mode. If set to true, no editable form input will be
displayed, instead this will display the formatted attribute value.
tried to check the documentation for that, but I still don't know how to do it on just one attribute.. I have:
'attribute' => 'user_id',
'label' => Module::t('app', 'USER_ID_LABEL'),
'headerOptions' => [
'style' => 'text-align: center;'
],
'contentOptions' => [
'style' => 'text-align: center;'
],
I need to sort that attribute values, how to do it? I checked in the documentation and tried like this:
'attribute' => [
'user_id' => [
'asc' => ['company_name' => SORT_ASC],
],
],
But this didn't work. I need to sort the values automatically by ASC. Thank you for the help
In your search query use :
orderBy(['company_name' => SORT_ASC])
I am trying to add a custom filter named Sort By Month in the grid view header here is an example of the previous version of the site which I am revamping see below image
I was looking into the layout option of the grid view and added a drop-down in the layout template before {items}
GridView::widget(
[
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout' => '{summary}{errors}' . \kartik\widgets\Select2::widget(
[
'model' => $searchModel,
'attribute' => 'filter_month',
'theme' => \kartik\widgets\Select2::THEME_DEFAULT,
'data' => $searchModel->getFilterMonths(),
'pluginEvents' => [
"select2:select" => 'function() { $("#w2").submit();}',
// 'select2:select'=> new \yii\web\JsExpression("function(){console.log('here')}"),
],
'options' => [
'placeholder' => '--Select Month--',
],
'pluginOptions' => [
'allowClear' => true,
'width' => '160px',
],
]
) . '{items}{pager}',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
'title',
'catalog',
'upc_code',
[
'attribute' => 'created_on',
'label' => 'Created On',
'filter' => \yii\jui\DatePicker::widget(['dateFormat' => 'yyyy-MM-dd', 'model' => $searchModel, 'attribute' => 'created_on']),
'format' => 'html',
],
[
'attribute' => 'status',
'label' => 'Status',
'format' => 'raw',
'value' => function ($data) {
switch ($data->status) {
case 0:
return "Being Edited (" . $data->created_on . ")";
break;
case 1:
return ($data->maxdate == '') ? 'Active' : 'Active';
break;
case 2:
return "Expired";
break;
}
},
],
['class' => 'yii\grid\ActionColumn'],
],
]
);
Now I want to submit the filters form when I select an option from the drop-down, but could not figure out how to attach the default filter submit event with the drop-down options so that it filters the results when I select any option in the drop-down.
For Custom filter you have used the perfect layout but you have to provide your custom field as a filterSelector.
"filterSelector" => "#". Html::getInputId($searchModel, 'AttributeName'),
I have this code in my gridview
....
[
'label'=>'Read',
'format' => 'html',
'value'=>function ($data) {
return Html::a('Read',Url::to(['readmessage/read/','q'=>$data->message_id]), ['data' => ['confirm' => 'My confirm question here?']]);
},
],
....
But above code is not generate data-confirm option in anchor link, and I have tried [data-confirm => 'My confirm question here?'] not working too.
What's wrong with my code?
Change the format to 'raw':
[
'label'=>'Read',
'format' => 'raw',
'value'=>function ($data) {
return Html::a('Read',Url::to(['readmessage/read/','q'=>$data->message_id]), ['data' => ['confirm' => 'My confirm question here?']]);
},
],
Just use "data-confirm"
[
'label'=>'Read',
'format' => 'html',
'value'=>function ($data) {
return Html::a('Read',Url::to(['readmessage/read/','q'=>$data->message_id]), ['data-confirm' => 'My confirm question here?']);
},
],
I use export menu on my yii2 project. I download it from demos.krajee.com. I have been success to use it, but I want to edit content like in pdf, so it have title/header or footer or page number. How to make it?
There are at least two ways to do that.
For example you can set it as default setting in
Yii::$container->set('kartik\grid\GridView', [
'summary' => "Showing {begin} - {end} from {totalCount} records",
'captionOptions' => ['style' => 'font-size:0em;'],
'panel' => [
'heading' => false,
'before' => '{summary}',
'after' => '{pager}',
'footer' => false,
],
'hover' => true,
'toolbar' => [
'{export}',
'{toggleData}',
],
'export' =>[
'showConfirmAlert' => false,
],
'exportConfig' => [
kartik\grid\GridView::PDF => [
'label' => 'Save as PDF',
'config' => [
'methods' => [
'SetHeader' => ['Header'],
'SetFooter' => ['Footer whatever: ' . strftime("%c") . '||Page {PAGENO}'],
]
],
],
],
...
Or pass the settings individually to each widget in every view.
You can use methods in wrapper http://demos.krajee.com/mpdf#settings (look for methods) or directly from mpdf class if you need something more complicated.