Why is the button page on my gridview not shown? - yii2

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',
],
..........

Related

Yii2 gridview buttons problem (possibly after pjax)

<?= 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'

Specify Font Size of Gridview in yii2

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;']
]

Yii2 Custom filter Dropdown for gridview

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'),

how to show json formated data in GridView

I want to show json formated data in gridview. I have following:
Json Data:
[{"c_id":1,"c_name":"Marokand","c_logo":"Marokand","c_slogan":"Marokand","c_address":"Tashkent Amir Temur, Uzbekistan","c_website":"www.maroqand.uz","c_email":"info#maroqand.uz","c_owner":"someone",},{"c_id":2,"c_name":"Apple LLC","c_logo":"","c_slogan":"","c_address":"","c_website":"","c_email":"","c_owner":""}
In my view file, I have following code:
<?= GridView::widget([
'dataProvider'=>$dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'c_id',
'c_name',
'c_logo',
'c_slogan',
'c_address',
// 'c_website',
// 'c_email:email',
// 'c_owner',
// 'c_short_description:ntext',
// 'c_description:ntext',
// 'c_history:ntext',
// 'c_goal:ntext',
// 'cci_memerbship_id',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
How can I show json data in gridview?
Use ArrayDataProvider: Refer Link
On controller file first decode json data like this and init data provider:
use yii\data\ArrayDataProvider;
use yii\helpers\Json;
$data = Json::decode("YOUR JOSN DATA", true);
$dataProvider = new ArrayDataProvider([
'allModels' => $data,
'pagination' => [
'pageSize' => 10,
],
'sort' => [
'attributes' => ['c_id'],
],
]);
on view side:
<?= GridView::widget([
'dataProvider'=>$dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'c_id',
'c_name',
'c_logo',
'c_slogan',
'c_address',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>

Kartik export widget not export search result Yii2

Fighting form last 3 days not able to find what exactly problem is. When after search I export data it export all data, expected to export search result.Please help!
My Controller
public function actionAdvancesearch()
{
$searchModel = new CandidateSearch();
$model = new Candidate();
$dataProvider1 = $searchModel->search(Yii::$app->request->queryParams);
if(Yii::$app->request->post()){
$postedData=Yii::$app->request->post();
$searchModel = new CandidateSearch();
$dataProvider1 = $searchModel->searchAdvanced();
return $this->render('candidateAdvSearch', ['dataProvider1' => $dataProvider1,
'model' => $model ,
'searchModel' => $searchModel,
'posted'=>"posted",
'postedData'=>$postedData]);
}else{
return $this->render('candidateAdvSearch', ['searchModel' => $searchModel, 'model' => $model, 'dataProvider1' => $dataProvider1]);
}
}
View
Pjax::begin();
if($dataProvider1){
$gridColumns = [
[
'attribute'=>'HRMS_candidateID',
'label'=>'Candidate ID',
'vAlign'=>'middle',
'width'=>'190px',
'value'=>function ($model, $key, $index, $widget) {
return $model->HRMS_candidateID;
},
'format'=>'raw'
],
[
'attribute'=>'HRMS_candidateFirstName',
'label'=>'Candidate FirstName',
'vAlign'=>'middle',
'width'=>'190px',
'value'=>function ($model, $key, $index, $widget) {
return $model->HRMS_candidateFirstName;
},
'format'=>'raw'
],
[
'attribute'=>'HRMS_candidateLastName',
'label'=>'Candidate LastName',
'vAlign'=>'middle',
'width'=>'190px',
'value'=>function ($model, $key, $index, $widget) {
return $model->HRMS_candidateLastName; },
'format'=>'raw'
],
];
$fullExportMenu = ExportMenu::widget([
'dataProvider' => $dataProvider1,
'columns' => $gridColumns,
'target' => ExportMenu::TARGET_POPUP,
'fontAwesome' => true,
'pjaxContainerId' => 'kv-pjax-container',
'dropdownOptions' => [
'label' => 'Full',
'class' => 'btn btn-default',
'itemsBefore' => [
'<li class="dropdown-header">Export All Data</li>',
],
],
]);
// Generate a bootstrap responsive striped table with row highlighted on hover
echo GridView::widget([
'dataProvider' => $dataProvider1,
'columns' => $gridColumns,
'pjax' => true,
'pjaxSettings' => ['options' => ['id' => 'kv-pjax-container']],
'panel' => [
'type' => GridView::TYPE_PRIMARY,
'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i> Candidate Advanced Search</h3>',
],
'toolbar' => [
$fullExportMenu,
],
'striped'=>true,
'hover'=>true,
'responsive'=>true,
'hover'=>true,
'resizableColumns'=>true,
'persistResize'=>false,
'columns' => $gridColumns,
]);
}
Pjax::end();