I'm printing gridview in pdf. The gridview is fine. But the cells are not filling in properly. I think if I can decrease the font a bit, the cell will be filled in properly. I've decreased the width. But the cells are being distorted.
Code of Gridview -
<?= GridView::widget([
'dataProvider' => $dataProvider1,
//'filterModel' => $searchModel,
'layout'=>"{items}",
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'hsncode',
[
'label' => 'Productname',
'attribute' =>'productname',
'headerOptions' => ['style' => 'width:20%'],
//'contentOptions' => ['class' => 'col-lg-1'],
//'format'=>['decimal',2]
],
'batchno',
//'expdate',
[
'attribute'=>'expdate',
'format'=>['DateTime','php:m-y'],
'headerOptions' => ['style' => 'width:6%'],
],
'mrp',
'rate',
'qty',
'free',
'discount',
[
'label' => 'Value',
'attribute' =>'value',
//'contentOptions' => ['class' => 'col-lg-1'],
'format'=>['decimal',2]
],
[
'label' => 'GST%',
'attribute' =>'gstpercent',
//'headerOptions' => ['style' => 'width:6%'],
//'contentOptions' => ['class' => 'col-lg-1'],
'format'=>['decimal',0]
],
[
'label' => 'Total',
'attribute' =>'totalamount',
'headerOptions' => ['style' => 'width:9%'],
//'contentOptions' => ['class' => 'col-lg-1'],
'format'=>['decimal',2]
],
],
]); ?>
Gridview looks like -
Please let me know how to specify the font in gridview.
you could use options for the grid container
<?= GridView::widget([
'dataProvider' => $dataProvider1,
//'filterModel' => $searchModel,
'layout'=>"{items}",
'options' => ['style' => 'font-size:12px;']
'columns' => [
or directly in column
<?= GridView::widget([
'dataProvider' => $dataProvider1,
//'filterModel' => $searchModel,
'layout'=>"{items}",
'options' => ['style' => 'font-size:12px;']
'columns' => [
[
'label' => 'your_label',
'attribute' =>'your_attribute',
'contentOptions' => ['style' => 'font-size:12px;']
]
Related
<?= GridView::widget([
'id' => 'CompanyGrid',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'floatHeader'=>true,
'floatOverflowContainer'=>true,
'floatHeaderOptions'=>['top'=>'0'],
'pjax'=>true,
'pjaxSettings' => [
'options' => [
'enablePushState' => false,
'enableReplaceState' => true,
]
],
'hover'=>true,
'toolbar' => [
'{export}',
'{toggleData}'
],
'panel' => [
'heading'=>'<h3 class="panel-title"><i class="glyphicon glyphicon-globe"></i> Companies</h3>',
'type'=>'secondary',
'before'=>Html::button('Create Company', ['value'=>Url::to('index.php?r=Company/company/create'), 'title' => 'Create Company', 'class' => 'btn btn-success', 'id' => 'modalButton']),
'after'=>false,
],
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
'CompanyID',
'CompanyName',
['class' => 'kartik\grid\ActionColumn',
'template' => '{view} {update} {delete}',
'buttons' => [
'view' => function($url, $model){
return Html::a('<span class="fa fa-eye"></span>', ['view', 'id' => $model->CompanyID], [
'class' => 'activity-view-link',
'data-pjax'=>'w0',
'title' => Yii::t('yii', 'View Company: '.$model->CompanyID),
'data-toggle' => 'modal',
'data-target' => '#modal',
]);
},
'update' => function($url, $model){
return Html::a('<span class="fa fa-edit"></span>', ['update', 'id' => $model->CompanyID], [
'class' => 'activity-view-link',
'title' => Yii::t('yii', 'Edit Company: '.$model->CompanyID),
'data-toggle' => 'modal',
'data-target' => '#modal',
]);
},
'delete' => function($url, $model){
return Html::a('<span class="fa fa-trash"></span>', ['delete', 'id' => $model->CompanyID], [
'class' => '',
'data' => [
'confirm' => 'Are you absolutely sure? This action is not reversible',
'method' => 'post',
],
]);
}
],
],
],
]); ?>
In Controller
public function actionView($id)
{
$model = Company::findOne($id);
return $this->renderAjax('view', [
'model' => $model,
]);
}
I am new in yii2-advance-apps and i am trying to solve this problem. Already worked on this problem and cannot find any solution for this.
The problem is when I click on the gridview actions buttons, it works. However, after PJax, the button just don't work anymore.
However, if i reload the page, the button works again.
How to solve this problem. Thank you in advance.
'data-pjax' => 0, in action buttons options and not 'w0'
How to hide history dropdown list in Yii2 kartik select2?
This is my source code:
<div class="col-sm-offset-2 col-sm-10" style="margin-left:135px;margin-bottom:15px">
<label class="control-label">Range Perjalanan Dinas</label>
<?= DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'model' => $model,
'attribute' => 'tgl_mulai',
'attribute2' => 'tgl_selesai',
'options' => ['placeholder' => 'Start date'],
'options2' => ['placeholder' => 'End date'],
'form' => $form,
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'autoclose' => true,
]
]); ?>
</div>
Try 'autocomplete' => 'off' in your date picker options:
<?= DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'model' => $model,
'attribute' => 'tgl_mulai',
'attribute2' => 'tgl_selesai',
'options' => ['placeholder' => 'Start date','autocomplete' => 'off'],
'options2' => ['placeholder' => 'End date'],
'form' => $form,
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'autoclose' => true,
]
]); ?>
You may have to turn off the autocomplete in your form element
Turning off form autocomplete
I have 4 columns in my GridView, which contains the data I need, but now I need one more column. How can I create it in my GridView?
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'surname',
'employment_date',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Thanks for the help
you can add more columns according to yii api:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'surname',
'employment_date',
[
'class' => DataColumn::className(), // this line is optional
'attribute' => 'name',
'format' => 'text',
'label' => 'Name',
],
['class' => CheckboxColumn::className()],
['class' => 'yii\grid\ActionColumn'],
]
]); ?>
you can read this link
<?= GridView::widget([
....
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'surname',
'employment_date',
'columns'=>[
'attribute'=>'New Column',
'value'=>'tbl.new_column'
],
//OR This
new_column,
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
I'm trying to use kartik gridview and got the following error. -
Undefined variable: gridColumns
I've checked - Yii2: Kartik Gridview sum of a column in footer. But didn't find the issue in my code.
Code of index.php -
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'showPageSummary' => true,
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
[
'attribute'=>'s_period',
'filter'=>ArrayHelper::map(Salary::find()->asArray()->all(), 's_period', 's_period'),
],
's_empid',
's_empname',
[
'attribute'=>'s_epf',
'pageSummary'=>true
],
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
if you assign manually the columns you don't need a var iwth columns specification so remove it
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//'columns' => $gridColumns,
'showPageSummary' => true,
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
[
'attribute'=>'s_period',
'filter'=>ArrayHelper::map(Salary::find()->asArray()->all(), 's_period', 's_period'),
],
's_empid',
's_empname',
[
'attribute'=>'s_epf',
'pageSummary'=>true
],
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
i have model from "feedbackmodel" :
public function search($params)
{
$query = Feedback::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> ['defaultOrder' => ['TANGGAL'=>SORT_DESC]],
'pagination' => array('pageSize' => 10),
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'ID_KOMENTAR' => $this->ID_KOMENTAR,
'id' => $this->id,
'TANGGAL' => $this->TANGGAL,
]);
$query->andFilterWhere(['like', 'KOMENTAR', $this->KOMENTAR]);
return $dataProvider;
}
and the gridview code like this:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout'=>"{items}",
'tableOptions' => ['class' => 'table table-bordered table-hover'],
'showFooter'=>false,
'showHeader' => false,
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
],
'columns' => [
[ 'attribute' => 'iduser.photo',
'format' => 'html',
'value'=> function($data) { return Html::img($data->imageurl) . " <p class='feedback-username'>" . $data->username . "</p>"; },
'contentOptions'=>['style'=>'max-width: 10px; max-height: 10px'],
],
[ 'attribute' => 'KOMENTAR',
'format' => 'raw',
'value' => function($model) { return $model->KOMENTAR ."<br><p class='feedback-date'>". $model->TANGGAL ."</p>";},
],
[ 'class' => 'yii\grid\ActionColumn',
'contentOptions'=>['style'=>'width: 5px;'],
'template' => '{update} {delete}'
],
],
]); ?>
But why the page button is not shown, its limited but i can see the other data bcos the i cant find the button next or prev to the other page
I test your code
if I remove the layout=>"{items}", the page buttons are show otherwise not (i think your layout assignment mean show only the item and not the pager) try simply comment it
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//'layout'=>"{items}",
'tableOptions' => ['class' => 'table table-bordered table-hover'],
'showFooter'=>false,
'showHeader' => false,
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
],
..........