IasPager pager not working after ajax update on clistview - php

Yii infinite scroll extention: "IasPager pager" not working after ajax update on clistveiw.
It's working fine before ajax call but after ajax call when i update listview it's not working.
$this->widget('zii.widgets.CListView', array(
'id' => 'VideoList',
'dataProvider' => $dataProvider,
'itemView' => '_view',
'template' => '{items} {pager}',
'pager' => array(
'class' => 'ext.infiniteScroll.IasPager',
'rowSelector'=>'.row',
'listViewId' => 'VideoList',
'header' => '',
'loaderText'=>'Loading...',
'options' => array('history' => false, 'triggerPageTreshold' => 2, 'trigger'=>'Load more'),
)
)
);

I have found solution of this, it works fine.
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'/products/viewProductList',
'summaryText'=>false,
'emptyText'=>"<p> Coming Soon!!</p>",
'id'=>'ajaxProductListView',
'cssFile'=>Yii::app()->baseUrl.'/css/mycustom.css',
'template' => '{items} {pager}',
'ajaxUpdate'=>true,
'pager' => array(
'class' => 'ext.infiniteScroll.IasPager',
'rowSelector'=>'.ademo',
'listViewId' => 'ajaxProductListView',
'header' => '',
'loaderText'=>'Loading',
'options' => array('history' => false, 'triggerPageTreshold' => 1, 'trigger'=>'Load more'),
),
'afterAjaxUpdate'=>"function(id, data) {
$.ias({
'history': false,
'triggerPageTreshold': 1,
'trigger': 'Load more',
'container': '#ajaxProductListView',
'item': '.ademo',
'pagination': '#ajaxProductListView .pager',
'next': '#ajaxProductListView .next:not(.disabled):not(.hidden) a',
'loader': 'Loading...'
});
}",
));?>

Related

How to call ajax through Bootstrap button in yii

I want to use Ajax through bootstrap button in Yii, and want to pass textfield values though that Ajax call.
here's the button code, where should i put the Ajax code for this button.
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD')); ?>
try this
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD',
'ajaxOptions' => array(
'type' => 'Post',
'url' => $this->createURL('url'),
'data' => Yii::app()->request->csrfTokenName."=".Yii::app()->request->getCsrfToken()."&action=cancel",
'success'=>"js:function(vals){
}",
)
)); ?>
another eg:
$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'ajaxButton',
'label' => 'Label Here',
'type' => 'danger',
'icon' => 'play white',
...
'ajaxOptions' => array(
'success' => '...',
'error' => '...',
'beforeSend' => '...',
)
));

Populate values in Zend Form multi-select option

So my form is
class Form_Group_ShareGroup extends Form_Abstract
{
public function init()
{
$this->setAttrib('class', 'shareForm');
//Row 1
$this->addElement('select', 'groups', array(
'decorators' => $this->getElementDecorators(),
'label' => Zend_Registry::get('Zend_Translate')->translate('Groups_Colon'),
'style' => 'width:320px;',
'multiple' => true,
'data-help' => Zend_Registry::get('Zend_Translate')->translate('Please_Select_Groups_Share')
));
$this->addElement('select', 'users', array(
'decorators' => $this->getElementDecorators(),
'label' => Zend_Registry::get('Zend_Translate')->translate('Users_Colon'),
'style' => 'width:320px;',
'multiple' => true,
'data-help' => Zend_Registry::get('Zend_Translate')->translate('Select_Users_To_Share_Group_With')
));
//Row 2
$this->addElement('button', 'share', array(
'decorators' => $this->buttonDecorators,
'required' => false,
'ignore' => true,
'type' => 'submit',
'label' => 'Share',
'class' => 'btn primary'
));
}
}
and I want to populate some user data into "users" element.
example could be :
array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' )
How can I achieve this ?
I have use populate method but it didnt worked out.
to view the form I am using :
$usersGroup = new Form_Group_ShareGroup();
$this->view->usersGroup = $usersGroup;
Please help !
Thanks for reading .
Try this:
//$data = array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' );
$usersGroup = new Form_Group_ShareGroup();
$usersGroup->getElement('users')->setMultiOptions($data);

when I click view button in CGridView, it is opened in a new window

I used from CGridView in framework Yii, I want when I click view button , it is opened in a new window
how can I add of "_new" of target ?
Add 'options' => array('target'=>'_new') to CButtonColumn configuration array in CGridView
array(
'class'=>'zii.widgets.grid.CButtonColumn',
'template' => '{view}',
'buttons'=>array(
'view' => array(
'url' => '', // view url
'options' => array('target' => '_new'),
),
),
),
You can provide the html properties by using 'options' property.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('class' => 'newWindow'),
),
),
),
),
));
?>
But, Opening a new window is browser dependent. With target="_blank" and target="_new" link will be opened in new tab in Mozilla, But in IE you will get new window. So user javascript to generate new window.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('class' => 'newWindow'),
),
),
),
),
));
?>
Keep this jQuery in your .js file
<script>
$(document).ready(function()
{
$(".newWindow").click(function(e)
{
e.preventDefault();
var url=$(this).attr('href');
window.open(url, "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=100, left=100, width=1020, height=500");
});
});
</script>
You can use this
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('target' => '_blank'),
),
),
),
),
));
?>

Yii Cgridview Filter Input Box Not Showing Search String After Searching

i'm facing an issue with the filter input box in CGridView. So the filter is showing the correct result after entering the search string in the filter input box and hitting enter, but the input box is getting cleared after the result is being shown. This makes it quite inconvenient for the user to see what they was searching for because the filter input box is empty while the grid shows the correct search results.
Here are the code.
entry view name ::newsReleases.php
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'product-news-grid-' . $id,
'itemsCssClass' => 'table table-striped',
'htmlOptions' => array(
'class' => 'news-datagrid',
),
'dataProvider' => $dataProvider->searchProductNews($symbol),
'filter' => $dataProvider,
'enableHistory' => false,
'ajaxUpdate' => 'product-news-grid-' . $id,
'ajaxUrl' => Yii::app()->createUrl('/realTime/AjaxUpdateProductNews'),
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 5,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'summaryCssClass' => 'label label-warning',
'columns' => array(
array(
'name' => 'headlines',
'header' => 'Headlines',
'value' => function($data) {
return '<div class="product-news"> <a target="_blank" href="' . $data->link . '" > ' . $data->headlines . '</a></div>';
},
'type' => 'raw',
),
array(
'name' => 'publish_date',
'header' => 'Date',
'value' => function($data) {
return '<span class="news-pub-date">' . $data->publish_date . '</span>';
},
'type' => 'raw',
)
)
));
?>
<!-- Now this script had to be included again in order to make the ajax sorting and pagination work, or else none of the ajax functionality is working. Remember when getting stuck with ajax update in grid views always use this script -->
<script type="text/javascript" src="/ProductAnalysis/assets/dd5f9a70/gridview/jquery.yiigridview.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
jQuery('[data-toggle=popover]').popover();
jQuery('body').tooltip({
"selector": "[data-toggle=tooltip]"
});
jQuery('#product-news-grid-' + $('#symbol-id').text()).yiiGridView({
'ajaxUpdate': ['product-news-grid-' + $('#symbol-id').text()],
'ajaxVar': 'ajax',
'pagerClass': 'pagination',
'loadingClass': 'grid-view-loading',
'filterClass': 'filters',
'tableClass': 'table table-striped',
'selectableRows': 1,
'enableHistory': false,
'updateSelector': '{page}, {sort}',
'filterSelector': '{filter}',
'url': '/ProductAnalysis/index.php/realTime/AjaxUpdateProductNews',
'pageVar': 'News_page',
'afterAjaxUpdate': function() {
jQuery('.popover').remove();
jQuery('[data-toggle=popover]').popover();
jQuery('.tooltip').remove();
jQuery('[data-toggle=tooltip]').tooltip();
$('#News_headlines').change(function() {
var inputVal = $(this).val();
$('#News_headlines').val(inputVal);
});
}
});
});
/*]]>*/
</script>
Here is the controller action named AjaxUpdateProductNews
public function actionAjaxUpdateProductNews() {
$dataProvider = new News();
$dataProvider->unsetAttributes();
if (isset($_GET['News'])) {
$dataProvider->attributes = $_GET['News'];
}
$id = explode("-", $_GET["ajax"]);
$realTime = RealTime::model()->findByPk($id[count($id) - 1]);
$this->renderPartial('_newsView', array(
'dataProvider' => new News(),
'symbol' => $realTime->symbol,
'id' => $realTime->id,
'headlines' => $_GET['News']['headlines'],
'publish_date' => $_GET['News']['publish_date']
));
}
and here is the view _newsView
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'product-news-grid-'. $id,
'itemsCssClass' => 'table table-striped',
'htmlOptions' => array(
'class' => 'news-datagrid',
),
'dataProvider' => $dataProvider->searchProductNewsSymbol($symbol, $headlines, $publish_date),
'filter' => $dataProvider,
'enableHistory' => false,
'ajaxUpdate' => 'product-news-grid-'. $id,
'ajaxUrl' => Yii::app()->createUrl('/realTime/AjaxUpdateProductNews'),
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 5,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'summaryCssClass' => 'label label-warning',
'columns' => array(
array(
'name' => 'headlines',
'header' => 'Headlines',
'value' => function($data) {
return '<div class="product-news"> <a target="_blank" href="'. $data->link .'" > '. $data->headlines .'</a></div>';
},
'type' => 'raw',
),
array(
'name' => 'publish_date',
'header' => 'Date',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->publish_date .'</span>';
},
'type' => 'raw',
)
)
));
?>
Now like i said the filter is showing the result, but the input box is getting cleared after it shows the result. I tried to reinsert the val in the input box using jQuery's change() handler, but it doesn't works.
Please provide any sort of advice on how to retain the search string value in the filter box. Oh, btw other grids on the sites are working flawlessly, so its not a problem with missing files.
Thanks in advance,
Maxx
Ok i've made a mistake in the renderpartial code() which caused this error. Simply changing
'dataProvider' => new News() to 'dataProvider' => $dataProvider fixed the issue. Hope it helps someone who is facing the same issues.
The working controller code
public function actionAjaxUpdateProductNews() {
$dataProvider = new News();
$dataProvider->unsetAttributes();
if (isset($_GET['News'])) {
$dataProvider->attributes = $_GET['News'];
}
$id = explode("-", $_GET["ajax"]);
$realTime = RealTime::model()->findByPk($id[count($id) - 1]);
$this->renderPartial('_newsView', array(
'dataProvider' => $dataProvider,
'symbol' => $realTime->symbol,
'id' => $realTime->id,
'headlines' => $_GET['News']['headlines'],
'publish_date' => $_GET['News']['publish_date']
));
}

Yii renders only one page without layout

I have a weird problem. I copied my website into production environment (from windows to ubuntu). I correct few big/small letter issues and app started to work fine. Until I entered one page that looks like it's being rendered without layout. There is no error.
Also - firebug shows no css styles or anything. At HTML source there is lack of layout code too.
What could be the reason of that?
EDIT:
controller part:
$dataProvider = Projects::model()->getInviteProjectsProvider();
$this->render('invite', array(
'dataProvider' => $dataProvider
));
It returns CActiveDataProvider.
View:
<?php
$this->breadcrumbs=array(
'Projekty' => array('admin'),
'Zapraszanie',
);
$this->renderPartial('_allMenu');
?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->module->assetsUrl; ?>/css/projects.css"/>
<h1>Projekty aktywne - zapraszanie</h1>
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id' => 'invite-grid',
'type' => 'striped condensed',
'dataProvider' => $dataProvider,
'rowCssClassExpression' => '($data->leftCustomers<100) ? "error":""',
'columns' => array(
array(
'name' => 'idProject',
'htmlOptions' => array('width' => '60px', 'style' => 'text-align: right;', 'class' => 'gridIdColumn'),
),
'name',
array(
'name' => 'leftCustomers',
'header' => 'Pozostało <i class="icon-info-sign" rel="tooltipbootstrap" data-original-title="Gdy wartość ta jest mniejsza niż 100 - rekord jest podświetlony na czerwono"/>',
),
'confirmStart',
'presentationDate',
array(
'class' => 'bootstrap.widgets.TbRelationalColumn',
'name' => 'Statystyki',
'value' => '"Pokaż"',
'url' => $this->createUrl('dynamicProjectStats')
),
array(
'header' => 'Postęp <i class="icon-info-sign" rel="tooltipbootstrap" data-original-title="Liczba zaproszeń / Limit zaproszeń"/>',
'value' => function($data)
{
$prc = round(($data->projectMaxInvites > 0) ? ($data->projectInvites)/ $data->projectMaxInvites * 100 : 0, 2);
Controller::widget('bootstrap.widgets.TbProgress', array(
'percent' => $prc,
'htmlOptions' => array(
'style' => 'height: 20px; margin-bottom: -20px',
'rel' => 'tooltipbootstrap',
'data-original-title' => $prc." %",
),
));
},
),
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'template' => '{view}{update}{delete}',
'htmlOptions' => array(
'style' => 'width: 40px;',
),
),
array(
'header' => '',
'htmlOptions' => array('style' => 'width: 43px'),
'value' => function($data)
{
$this->renderPartial('partials/_actionMenu', array('idProject' => $data->idProject, 'activated' => true, 'afterAction' => 'removeActiveProject'));
}
),
array(
'header' => '',
'value' => function($data)
{
$this->renderPartial('partials/_statMenu', array('idProject' => $data->idProject, 'showIcon' => true));
}
),
)
));
?>
I noticed that if I comment out the columns where function($data) is used - it shows fine. When I leave it - there is no layout displayed.
EDIT2:
Maybe I should notice the fact that inside partials/_statMenu and partials/_actionMenu there is a bootstrap.widgets.TbButtonGroup widget rendered.
Try:
Yii::app()->controller->renderPartial(...)
Instead of:
$this->renderPartial(...)

Categories