beforeAjaxUpdate on delete cgridview yii - php

Here is my code
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'dsfsd',
'dataProvider' => $model->search(),
'filter' => $model,
'cssFile' => false,
'itemsCssClass' => 'table table-striped',
'beforeAjaxUpdate'=>'js:function(id,options){$.blockUI({
message: "Please wait",
//showOverlay: false,
css: {
border: "none",
padding: "15px",
"-webkit-border-radius": "10px",
"-moz-border-radius": "10px",
opacity: 1,
"z-index": "9999"
}
});}',
'columns' => array(
array(
'header' => '#',
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->id),array("abc/m/".CHtml::encode($data->id)."/info"))',
'htmlOptions' => array('width' => '40px'),
'filter' => CHtml::activeTextField($model, 'id', array('placeholder' => 'search by id')),
), array(
'header' => 'First name',
'name' => '$data.user.f_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->f_name)',
), array(
'header' => 'Last name',
'name' => '$data.user.l_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->l_name)'
),
array(
'class' => 'CButtonColumn',
'template' => '{update} {delete}',
//'updateButtonUrl' => 'Yii::app()->createUrl("abc/xyz?id=".$data->id."&c_id=".$data->c_id)',
'deleteButtonUrl' => 'Yii::app()->createUrl("xyv/abc",array("uid"=>$data->id))',
),
),
));
Well, what I want is that the operations under beforeAjaxUpdate will work only when delete button is clicked, not for any other ajax actions like on search or update. How is it possible?

You can add callback function to delete button:
http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail
You should set click option in buttons config array:
'columns' => array(
...
'buttons'=>array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',
'buttons'=>array(
'delete'=>array(
'click'=>'function(){/*your code here*/}'
)
)
)
...
)
You can return false from callback function to prevent deleting.

Related

How to get sort value on Gridview Yii

$this->widget(
'bootstrap.widgets.TbGridView',
array(
'id' => 'birthday-report-grid',
'dataProvider' => $model->search(),
'selectableRows' => 0,
'ajaxType' =>'get',
'template' => GridHelper::getTemplate(),
'type' => GridHelper::getType(),
'enablePagination' => TRUE,
'enableSorting' => TRUE,
'filter' => $model,
'pager' => GridHelper::getPager(),
'columns' => array(
array(
'header' => Yii::t('backend', 'Customer Name'),
'name' => 'fullname',
'type' =>'raw',
'value' => '$data["customer_id"] ? CHtml::link($data->getCompleteName(),array("/admin/customer/profile/".$data["customer_id"]."/dashboard")) : $data->getCompleteName()',
'filter'=>CHtml::activeTextField($model, 'fullname').CHtml::activeTextField($model, 'month', array('id'=>'Filmonth','style' => 'Display:none;')),
),
array(
'name' => 'email',
'header' => Yii::t('backend', 'Customer Email'),
),
array(
'name' => 'birthday_month',
'value' => '!empty($data->birthday_month) && $data->birthday_month > 0 ? date("F", strtotime("1-".$data->birthday_month."-1970")) : ""',
'filter' => false,
),
array(
'name' => 'primary_phone',
'header' => Yii::t('backend', 'Customer Contact'),
'filter' => false,
),
array(
'header' => Yii::t('backend', 'Total Order (To Date)'),
'value' => '$data->getNoOfOrder2()',
'htmlOptions' => array('style' => 'text-align: right'),
'footer' => '<div style="text-align: right">'.$model->getTotalOfOrder().'</div>',
),
array(
'header' => Yii::t('backend', 'Total Order Amount (To Date)'),
'value' => 'CurrencyHelper::formatPrice($data->getTotalAmountOfOrderByCustomerId2())',
'htmlOptions' => array('style' => 'text-align: right'),
'footer' => '<div style="text-align: right">'.CurrencyHelper::formatPrice($model->getGrandTotalAmountOrder()).'</div>',
),
)
)
);
WHat i want is how to get sort value (Example: sort=fullname) what i want is "fullname"
i mean when i click column sorting on Customer Fullname , i can get the sort value using Jquery
Example image:
When Click sorting on "Customer Fullname" i need get sorting value (sort="VALUE")
Please help me thanks

Cannot use object of type TbGridView as array Yiibooster

I'm trying to set up a new grid view in yii booster while passing a variable through at the start of the view to sort the formatting.
I presume I am not passing the variable properly by this line
$gridColumns = $this->widget('booster.widgets.TbGridView', array(
How would I go about using this variable? I can create a new form array okay not using yiibooster but with the widget activated it no longer likes the variable name
The issue is I'm getting the error in the title of the post.
$gridColumns = $this->widget('booster.widgets.TbGridView', array(
'id' => 'delegate-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
// 'id',
array(
'name' => 'forename',
'type' => 'raw',
'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
),
'surname',
// 'facilities',
// 'telephone',
// 'address_id',
/*
'logo_path',
*/
array(
'class' => 'booster.widgets.TbButtonColumn',
),
),
));
$groupGridColumns = $gridColumns;
$groupGridColumns[] = array(
'name' => 'firstLetter',
'value' => 'substr($data->surname, 0, 1)',
'headerHtmlOptions' => array('style' => 'display:none'),
'htmlOptions' => array('style' => 'display:none')
);
$this->widget('booster.widgets.TbGroupGridView', array(
'id' => 'user-grid',
'type' => 'striped bordered condensed highlight',
//'template' => "{items}",
'dataProvider' => $model->search(),
'filter' => $model,
'extraRowColumns' => array('firstLetter'),
'extraRowExpression' => '"<b style=\"font-size: 3em; color: #333;\">".substr($data->surname, 0, 1)."</b>"',
'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
'columns' => $groupGridColumns,
));
It is because you are giving an object of type CGridView to TbGroupGridView as parameter.
$groupGridColumns = $gridColumns;
You are putting an object of type TbGridView($gridColumns) in $groupGridColumns and then give it to your TbGroupGridView, but TbGroupGridView columns property expects its value be an array of arrays(definition of columns) and so throws new exception when in the first cell of $groupGridColumns find an object.
You do not need the first part and with some changes, your code should work fine with filtering enabled.
$this->widget('booster.widgets.TbGroupGridView', array(
'id' => 'user-grid',
'type' => 'striped bordered condensed highlight',
'dataProvider' => $model->search(),
'filter' => $model,
'extraRowColumns' => array('firstLetter'),
'extraRowExpression' => '"<b style=\"font-size: 3em; color: #333;\">".substr($data->surname, 0, 1)."</b>"',
'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
'columns' => array(
array(
'name' => 'forename',
'type' => 'raw',
'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
),
'surname',
array(
'name' => 'firstLetter',
'value' => 'substr($data->surname, 0, 1)',
'headerHtmlOptions' => array('style' => 'display:none'),
'htmlOptions' => array('style' => 'display:none')
)
array(
'class' => 'booster.widgets.TbButtonColumn',
),
)
));

Yiibooster editable widget inside popover widget

I'm building website using yii 1.1 framework and Clevertech YiiBooster extension.
Is there an easy way to render few "editable field" widgets inside the popover widget ?
Please see the code below. Any suggestions are welcome.
Main view:
....
$this->widget(
'booster.widgets.TbButton', array(
'label' => 'Right popover',
'context' => 'warning',
'buttonType' => 'button',
'size' => 'extra_small',
'htmlOptions' => array(
'id' => uniqid(),
'data-html' => true,
'data-title' => 'A Title',
'data-placement' => 'right',
'data-content' => $this->renderPartial('VIEW', array('data'=>$data), true, true),
'data-toggle' => 'popover'
),
)
);
....
partial view:
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);

Delete operation in CGridView in yii.

I am using CGRidVeiw to list my records from database,
In each records I have an edit and delete button.Everthing is working fn9 other than the delete operation,actually its is showing an error after clicking the delete icon,but its still working.Below is the snap of what it actually look like,
After hitting refresh its not showing the record.
I have my view and contoller as below.
//contoller
public function actionDeleteEmployer() {
$model = new AdminDeleteEmployer();
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$query = "DELETE FROM user,jobs USING user INNER JOIN jobs ON jobs.user_id = user.id WHERE user.id =$id";
Yii::app()->db->createCommand($query)->queryAll();
$this->redirect('admin/site/ManageEmployers');
}
///view
Manage Employers
<div class="form">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'ajaxUpdate'=>false,
// 'filter' => $model,
'columns' => array(
array(
'name' => ' Employer ID',
'type' => 'raw',
'value' => 'CHtml::encode($data->id)',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Created On',
'type' => 'raw',
'value' => 'CHtml::encode( date("m-d-Y",strtotime($data->created)))',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Account Name',
'type' => 'raw',
'value' => 'CHtml::encode($data->name)',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Email',
'type' => 'raw',
'value' => 'CHtml::encode($data->email)',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Last Active On',
'type' => 'raw',
'value' => 'CHtml::encode( date("m-d-Y",strtotime($data->modified)))',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'class' => 'CButtonColumn',
'deleteConfirmation' => 'Are you sure you want to delte this item?',
'template' => '{view}{delete}',
'buttons' => array(
'view' => array('label' => 'view',
'url' => 'Yii::app()->controller->createUrl("ViewEmployerActivity",array("id"=>$data["id"]))'),
'delete' => array('label' => 'delete',
'url' => 'Yii::app()->controller->createUrl("DeleteEmployer",array("id"=>$data["id"]))'),
)
)
),
));
?>
</tbody>
</table>
redirect to admin action
Yii::app()->db->createCommand($query)->execute();
$this->redirect(array('admin'))

Yii Bootstrap GridView yiiPager replacement

I am trying to generate a Yii GridView using Bootstrap
On the ul element, i have the yiiPager class and i need to set it as the pagination class;
code here:
<h1>Manage Request Ms</h1>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'request-m-grid',
'type' => array('striped', 'bordered', 'condensed'),
'dataProvider' => $model->search(),
'template' => '{pager}{items}{pager}',
'filter' => $model,
'pager' => array(
'header' => '',
'hiddenPageCssClass' => 'disabled',
'maxButtonCount' => 3,
'cssFile' => false,
// 'class' => 'pagination',
'prevPageLabel' => '<i class="icon-chevron-left"></i>',
'nextPageLabel' => '<i class="icon-chevron-right"></i>',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'pagerCssClass' => 'pagination',
'rowCssClass' => 'pagination',
'columns' => array(
'id',
'domain_id',
'start',
'stop',
'delta1',
'delta2',
array(
'class' => 'CButtonColumn',
),
),
));
?>
$this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'request-m-grid',
....
'pager' => array('htmlOptions'=>array('class'=>'your_css_class')), // set whatever css class you want
));

Categories