I am using the Yii Framework, and I'm having issues with the bootstrap.widgets.TbGridView widget in conjunction with the Pager widget.
(Please note that I am new to Yii - so feel free to point out any obvious mistakes on my behalf)
All the filtering works fine, however when I select any option from the 'Fulfilled' dropdown menu it changes the URL structure of the Pager.
For instance, by default when I view the Pager links in Firebug the URL looks like this:
3
However once I make a selection from the 'Fulfilled' dropdown, and try to use the Pager again it no longer works, and after inspecting it via Firebug the Pager links have all changed dramatically to this:
3
I would expect the URL to retain a very similar structure as the initial link above.
Below is the view code for the page
<div class="row-fluid">
<div class="inner">
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'shoppurchases-grid',
'type' => 'striped bordered condensed',
'dataProvider' => $model->setPurchaseType('school')->search(10),
'filter' => $model,
'template' => '{summary}{items}{pager}',
'columns' => array(
array(
'header' => 'Product Image',
'value' => 'CHtml::image($data->product->displayImageUrl, $data->product->product_name, array("class"=>"grid-image"))',
'type' => 'raw',
),
array(
'header' => 'Product',
'name' => 'product.product_name',
'value' => '$data->product->product_name',
'filter' => CHtml::activeTextField($model, 'filterProductName', array('placeholder' => 'filter by product name')),
'type' => 'raw',
),
array(
'header' => 'Username',
'name' => 'user.firstname',
'value' => '($data->user instanceof MyUser) ? CHtml::link(CHtml::encode($data->user->username),array("/carrot/myuser/update","id"=>$data->user->user_id)) : ""',
'filter' => CHtml::activeTextField($model, 'filterUserName', array('placeholder' => 'filter by username')),
'type' => 'raw'
),
array(
'header' => 'Form Name',
'name' => 'user.form_name',
'value' => '($data->user instanceof MyUser) ? $data->user->form_name : ""',
'filter' => CHtml::activeTextField($model, 'filterFormName', array('placeholder' => 'filter by form name')),
'type' => 'raw'
),
array(
'header' => 'Student',
'name' => 'user.username',
'value' => '($data->user instanceof MyUser) ? $data->user->fullname : ""',
'filter' => CHtml::activeTextField($model, 'filterFirstName', array('placeholder' => 'filter by first name')),
'type' => 'raw'
),
array(
'header' => 'Price',
'name' => 'price',
'filter' => BHtml::activeCompareableTextField($model, 'price', array('placeholder' => 'filter by price')),
'type' => 'raw'
),
array(
'header' => 'Purchase Time',
'name' => 'purchase_time',
'value' => 'app()->dateFormatter->format("dd/MM/y H:m:s", $data->purchase_time)',
'filter' => BHtml::activeCompareableDateRange($model, 'purchase_time', array('placeholder' => 'filter by purchase time')),
'type' => 'raw'
),
array(
'header' => 'Fulfilled',
'name' => 'fulfilled',
'value' => user()->hasAuth(Group::READ_ONLY, "equal") ? '$data->fulfilled ? "Yes" : "No"' : 'CHtml::activeCheckBox($data, "fulfilled")',
'filter' => CHtml::activeDropDownList($model, 'fulfilled', array(0 => 'No', 1 => 'Yes'), array('prompt' => 'All')),
'type' => 'raw',
'htmlOptions' => array('class' => 'align-center'),
'headerHtmlOptions' => array('class' => 'align-center'),
),
array(
'name' => 'organisation_name',
'visible' => ((user()->hasAuth(Group::GROUP_ADMIN, 'equal')) && (!user()->hasState('view_org'))),
'filter' => CHtml::activeDropDownList($model, 'organisation_id', CHtml::listData(Organisation::model()->leaChildren, 'organisation_id', 'organisation_name'), array('prompt'=>'All Schools')),
),
array(
'header' => '',
'value' => 'CHtml::link("Refund", Yii::app()->controller->createUrl("bulk",array("id"=>$data->primaryKey)), array("class" => "btn btn-save", "name" => CHtml::activeName($data,"refunded")))',
'type' => 'raw',
'visible' => !user()->hasAuth(Group::READ_ONLY, "equal")
),
),
)); ?>
</div>
Thanks in advance - please remember I'm new to Yii
update...
I've checked the Firebug log and can see the GET request is failing (as it shows up in RED text in the Firebug log)
The URL is :
http://mysite.local/site/shop/purchases/admin/ShopPurchases%5BfilterProductName%5D//ShopPurchases%5BfilterUserName%5D//ShopPurchases%5BfilterFormName%5D//ShopPurchases%5BfilterFirstName%5D//ShopPurchases%5Bprice%5D//ShopPurchases%5Bpurchase_time%5D//ShopPurchases%5Bfulfilled%5D/0/ajax/shoppurchases-grid/ShopPurchases_sort/price?ajax=shoppurchases-grid
Once it tries to call this 'failed' URL the Pager stops working until I do a page refresh (e.g F5) and it returns to its default pager settings.
update 2...
The failed URL when loaded directly into the address browser for some reason will automatically attempt to add 'www.' at the start of the URL so the full url now looks like this..
http://wwwmysite.local/site/shop/purchases/admin/ShopPurchases[filterProductName]//ShopPurchases[filterUserName]//ShopPurchases[filterFormName]//ShopPurchases[filterFirstName]//ShopPurchases[price]//ShopPurchases[purchase_time]//ShopPurchases[fulfilled]/0/ShopPurchases_page/2/ajax/shoppurchases-grid?ajax=shoppurchases-grid
Is this something possibly related to my local htaccess file (this problem doesn't seem to exist on our 'live' version of the app.
I had to use some functionality to 'Remove Filters' in Yii for this to work - will post some code shortly.
Related
Is that possible to make alignment for grid view? As you see the picture above, the checkbox are out of the boxes. I think column should be need add something. Below is my part of the code:
'columns'=>array(
array(
'name' => 'id',
'class' => 'CCheckBoxColumn',
'selectableRows' => '99',
'checked' => 'true',
'htmlOptions'=>array('style'=>'text-align:center'),
),
array(
'name' => 'edesc',
'header' => 'School Type',
'headerHtmlOptions'=>array('style'=>'text-align:left')
),
you could try adding a proper style width for checkbox column (and for the edesc column)
array(
'name' => 'id',
'class' => 'CCheckBoxColumn',
'selectableRows' => '99',
'checked' => 'true',
'htmlOptions'=>array('style'=>'text-align:center; width: 10%;'),
),
array(
'name' => 'edesc',
'header' => 'School Type',
'headerHtmlOptions'=>array('style'=>'text-align:left; width: 90%;')
),
$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
I want to show a grid or editable table in my tab in the admin section
I managed to do the module and three tabs are been displayed .In one of the tab i want to show a editable grid i.e in the CHECKS tab
As shown in the below image,in the chek tab section i want to show a grid
In the constructor of my admin controller of my module ()
ie in addhealthcheckconfig\controllers\admin\HealthCheckConfigController.php
I am setting the field options to populate the tab ,below is my code:
$this->fields_options = array(
'appearance' => array(
'title' => $this->l('Manage your Health Check '),
'icon' => 'icon-html5',
'tabs' => array(
'TAB1' => $this->l('SUPPORT_GROUPS'),
'TAB2' => $this->l('CHECKS'),
'TAB3' => $this->l('REPORT RECIPIENTS'),
),
'fields' => array(
'SUPPORT_GROUPS' => array(
'title' => $this->l('SUPPORT GROUPS'),
'hint' => $this->l('Manage your Support Groups here'),
'type' => 'fields_list',
'name' => 'PS_LOGO',
'tab' => 'TAB1'
),
'CHECKS' => array(
'title' => $this->l('LIST OF AVAILABLE CHECKS '),
'hint' => $this->l('List of Available checks will be displayed here !!'),
'type' => 'text',
'list' => $this->fields_list = array(
'code' => array(
'title' => $this->l('code'),
'align' => 'text-center',
'remove_onclick' => true,
'search' => false,
),
'description' => array(
'title' => $this->l('description'),
'align' => 'text-center',
'remove_onclick' => true,
'search' => false,
),
'category' => array(
'title' => $this->l('category'),
'align' => 'text-center',
'remove_onclick' => true,
'search' => false,
),
),
'tab' => 'TAB2'
),
'REPORT_RECIPIENTS' => array(
'title' => $this->l('REPORT RECIPIENTS '),
'hint' => $this->l('List of Available checks will be displayed here !!'),
'tab' => 'TAB3'
),
) ));
In the TAB2 Section i am not sure what i need to put in the 'type' section , I tried with list , but yet I can not achieve what I am trying to do , also i am not sure how to assign the $this->fields_list to that type correctly
How to achieve this editable db grid in my tab ?
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.
i'm using PHP Yii framework, and came across a problem regarding adding Id and other attributes to a tab. I'm using yii bootstrap by the way as extension:
$tabs = array(
'item1' => array(
'label' => 'label1',
'content' => $content1,
),
'preview' => array(
'label' => 'Preview',
),
);
$this->widget('bootstrap.widgets.TbWizard',
array(
'id' => 'harvest-tabs',
'type' => 'tabs',
'tabs' => $tabs,
'pagerContent' => false,
));
How do i add an 'id' and 'class' property to each of the tab 'item1' and 'preview'?
i tried:
'item1' => array(
'label' => 'label1',
'content' => $content1,
'id' => 'some id'
'class' => 'some class'
),
'preview' => array(
'label' => 'Preview',
'id' => 'some other id'
'class' => 'some other class'
),
But this doesn't add a class to it. I only see <li>'s
that serves as the container for the tabs. Sorry i'm a newbie here. I'd appreciate any help Thanks!
You should try this:
'item1' => array(
'label' => 'label1',
'content' => $content1,
'htmlOptions'=>array(
'id' => 'some id'
'class' => 'some class'
),
),
I haven't tried it but I'm following yii bootstrap logic here. Tell me if it's not working.