yii2 : how to keep the url same in kartik grid view? - php

I am using kartik grid view to display my data in yii 2 with pjax enabled. Every time, I search a data in the grid view, the search is done using ajax but the url keeps changing. Is there a way to keep the url unchanged? Please help me with the solution. Here is my code:
<?php use kartik\grid\GridView;?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax'=>true,
'pjaxSettings'=>[
'neverTimeout'=>true,
],
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'hotel_id',
'name',
'address',
'phone_no',
'contact_person',
// 'email_address:email',
// 'website',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>

You can disable pushState feature like this:
'pjax' => true,
'pjaxSettings' => [
'options' => [
'enablePushState' => false,
],
],

Related

Render html in yii2 Gridview Widget

That's how I am rendering the values on a grid view
but instead of links I can see the textual value.
How can I make it render html instead of text?
In link column configuration add:
'format' => 'html',
or if you want some extra markup there
'format' => 'raw',
In case of raw remember to encode values coming from outside users because it's not done automatically.
A better way of doing this in Yii.
'value' => function ($data) {
return Html::a($data->name, [$data->url, 'someData' => $data->someData]);
}
Yii Doc: https://www.yiiframework.com/doc/api/2.0/yii-helpers-basehtml#a()-detail
A little late on the post but, hope it helps the in future.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
'email:email',
'timestamp:date',
[
'attribute'=>'Resume',
'format' => 'raw',
'class' => 'yii\grid\DataColumn', // can be omitted, as it is the default
'value' => function ($data) {
$url = "www.sample.com/contactform/resumes".$data->resumepath;
return Html::a('<i class="glyphicon glyphicon-download-alt"></i>', $url);
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>

Adding a class to Yii2 CRUD GridView

I've been trying to add a class to the images' column in the CRUD GridView in Yii2. So far, I've managed to display the image, but at its full width and height. I need to add a 'col-md-3' bs class to the image.
This is what I pulled off:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'emp_firstname',
'emp_lastname',
'emp_photo' => [
'format' => 'image',
'attribute' => 'emp_photo',
'value' => 'emp_photo',
'contentOptions' => ['class' => 'col-md-3'],
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
if you want to add id or class or both to the table
try this.
'tableOptions' => [
'id' => 'theDatatable',
'class'=>'table table-striped table-bordered'
],
form the column group you can use options http://www.yiiframework.com/doc-2.0/yii-grid-column.html#$options-detail
'emp_photo' => [
'format' => 'image',
'attribute' => 'emp_photo',
'value' => 'emp_photo',
'options' => ['class' => 'col-md-3'],
],
but you should complete the "bootstrap grid" in the other columns

yii2 jui datepicker doesn't working on pjax

i need datepicker on yii2 gridview. So i have used the jui extension. It was working fine. But when i go for pjax it automatically reloads the page every time when i change the datepicker value. If anyone knows about this please guide me.
Here is my code:
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\jui\DatePicker;
use yii\helpers\ArrayHelper;
Pjax::begin();
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'td_created_datetime',
'filter' => \yii\jui\DatePicker::widget([
'model' => $searchModel,
'attribute' => 'td_created_datetime',
'language' => 'en',
'dateFormat' => 'yyyy-MM-dd',
'clientEvents' => [
'change' => "function(e){
alert('occured');
e.preventDefault();
}"
],
]),
],
],
]);
Pjax::end();
?>

Outputting data from table after saving with ckeditor

Am saving data using the ckeditor in yii2 in my form model but when doing the view action it displays the html tags
CKEDITOR CODE:
<?= $form->field($model, 'case_description')->widget(CKEditor::className(),[
'editorOptions' => [
'preset' => 'full',
'inline' => false,
],
]);
?>
So after I save the data in the table its saved having the html codes
example of saved data:
<b>My new project being grilled</b>
So when viewing the data using yii2 detail and gridview it always shows the <b> instead of being bold.
How can I solve the problem
EXAMPLE: of grid view outputting it in the case_description column
<?= GridView::widget([
'summary'=>"",
'showOnEmpty'=>false,
'dataProvider' => $dataProviderb,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'case_description',
],
]) ?>
You just use the 'format' => 'row' in your GridView like:
<?= GridView::widget([
'summary'=>"",
'showOnEmpty'=>false,
'dataProvider' => $dataProviderb,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'case_description',
'format' => 'raw',
],
],
]) ?>

Setting the template property on Yii2 GridView / ActionColumn?

First ... old school, rusty Pascal/Clipper/VB developer trying to learn PHP and Yii2 at the same time.
Looking at http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$template-detail I should be able to easily remove the update and delete buttons in the ActionColumn ... I just don't know how / where to set the property.
Our GridView code is:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'last_name',
'first_name',
'email1:email',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
My gut tells me it's something to do with instantiating the ActionColumn class before we throw that in as a column ... but I've combed the forums and documentation and just can't find any example.
You are searching for the template properly. http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$template-detail
your column should be
[
'class' => 'yii\grid\ActionColumn',
'template' => "{view}",
],

Categories