clistview a path in itemView in yii - yii

I have a widget that renders a file. From there, it has a clistview. But the path is not working. I am getting the error require(): Filename cannot be empty.
So originally I had the page render from $model, but I realized I should be using clistview. It works fine if I just do a renderPartial $model but it doesn't work in clistview.
from my widget:
$this->renderFile(Yii::getPathOfAlias('application.views.grid'). '/index.php',
array('product'=>$product));
pass to my grid/index.php. I'm showing both ways I had. The top one works but I would need to do a foreach loop. I want to get rid of that due to pagination problems, so I want to use clistview.
<?php
// this works fine, but not what I want.
// $this->controller->renderPartial('//grid/_view',array(
// 'product'=>$product,
// ))
?>
<?php
// $path = '//grid/_view'; I've tried something like this and put it in itemView. It doesn't work.
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$product,
'itemView'=>'//grid/_view',
'template' => '{pager}{items}',
);
?>

You always can set path for itemView as alias
$this->widget('zii.widgets.CListView', array(
'itemView'=>'application.views.grid._view'

Related

Clistview With Pagination in Yii

I don't get along with pagination for one of my CListView. In my controller I fetch records to a CActivedataProvider by using a criteria and I pass that data provider to my CListView. I can see that database fetch is working fine since I can see all records in my CListView if I don't apply pagination.
The problem begins when pagination is turned on. I would like to see all records on a separate page with a pagination at the bottom.
What I'm doing wrong?
Thanks in advance,
Here is what I have in my controller:
if(isset($_POST['Lista']))
{
$model->attributes=$_POST['Lista'];
}
$egyedi_osszetevo_idk = Lista::getEgyediOsszetevoIdk($model->datum_tol, $model->datum_ig);
$criteria = new CDbCriteria();
$criteria->addInCondition("id", $egyedi_osszetevo_idk);
$count = EtelOsszetevo::model()->count($criteria);
$pages=new CPagination($count);
$pages->pageSize=1;
$pages->applyLimit($criteria);
$dataProviderEgyediOsszetevok = new CActiveDataProvider('EtelOsszetevo', array(
'criteria'=>$criteria,
'pagination'=>$pages,
));
$this->render('view',array('model'=>$model,
'egyedi_osszetevo_idk'=>$dataProviderEgyediOsszetevok,
));
Here is my CListView in my view file:
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$egyedi_osszetevo_idk,
'itemView'=>'_view',
));

yii CListView is not updating when we delete the records through ajax request

here i am using the ajax request to delete the record from the clistview the record is deleting succesfully but the list view is not updating if we refresh the page then only the record is removing from the clist view can any one help here is my code
<?php
echo CHtml::link(CHtml::encode('Delete'), $this->createUrl('delete', array('id' => $data['id'])), array(// for htmlOptions
'onclick' => ' {' . CHtml::ajax(array(
'type'=>'POST',
'beforeSend' => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
'url'=>$this->createUrl('delete', array('id' => $data['id'],'ajax'=>'delete')),
'complete'=>'js:function(jqXHR, textStatus){$.fn.yiiListView.update("firstlist");}'
)) .
'return false;}', // returning false prevents the default navigation to another url on a new page
)
);
here is the code for clistview
<?php $this->widget('zii.widgets.CListView', array(
'id' => 'firstlist',
'dataProvider'=>$dataProvider,
'itemView'=>'_beneview',
'enablePagination' => false,
'summaryText' => '',
)); ?>
You could use CHtml::ajaxLink for ajax request, but your way is also fine.
I have filtered CListView results also with paginations enabled, you can just look at the major things for updating list view on this link
Please check view part and updating script part.
Hope his will help.
Use CGridView, you can add CButtonColumn

Pagination with Search form not working

I am implementing pagination on my search result, on the very first page it is working fine, but the problem is when i click on 2 for second page results, it displays empty page.
In view i have:
$this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider,
'itemView'=>'_listing'));
while in my controller i have:
if (isset($_POST)
{
(......)
$dataProvider=new CArrayDataProvider($results,array(
'keyField' => 'brand_id',
'pagination'=>array(
'pageSize'=>5,
)));
//echo "<pre>"; print_r($dataProvider);exit;
$this->render('listing',array('dataProvider'=>$dataProvider, 'post' => $_POST));
}
The $results contains my search results, controller has a check if post is set or not, so when request for load of second page is sent to listing action, the post data is not set, so it does not enters the code and displays nothing.
How to make post data available to action when call for second page is done?
try this
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_listing',
'ajaxUpdate'=>'#divViewPanel',
'enablePagination'=>true
));

Yii load datepicker in partial view

Trying to load a block with a datepicker from a view.. but it loads only the textfield without datepicking feature. What am I doing wrong?
The create view
<?php echo $form->dropDownList($model,'operation_type',CHtml::listData(OperationType::model()->findAll(),
'id','name'),array(
'class'=>'span3',
'empty'=>'----- Type -----',
'id'=>'idOpType',
'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('operations/meta'),
//'dataType'=>'json',
'data'=>array('idOpType'=>'js:this.options[this.selectedIndex].innerHTML'),
'success'=>'function(data){
$("#opTypeBlock").html(data);
}',
),
)); ?>
The Controller Action
public function actionMeta(){
$data= new OperationsMeta();
$this->renderPartial('_meta',array('model'=>$data));
}
The view I am trying to load
<p>Select due date</p>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',array(
'attribute'=>'param',
'options'=>array(
'showAnim'=>'fold',
),
'model'=>$model,
'htmlOptions'=>array(
'style'=>'height:20px;',
'class'=>'inline',
'id'=>'datepickerOpType',
),
));
?>
Try
$this->renderPartial('_meta',array('model'=>$data), false, true);
so it loads JS files.
Use renderAjax() which injects into the rendering result with JS/CSS scripts and files which are registered with the view, as stated here.

Yii CListview -> pagination and AjaxLink/ajaxButton

I have problems regarding with pagination and Ajax form.
Here is my code for Controller:
$dataProvider = new CActiveDataProvider('User', array(
'pagination'=>array(
'pageSize'=>10,
),
));
$this->render('users',array(
'dataProvider'=>$dataProvider,
));
For view -> users:
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_user',
);
For render _users:
echo CHtml::ajaxLink($text, $this->createUrl('admin/deleteuser',array('id'=>$data->iduser)), array('success'=>"js:function(html){ alert('remove') }"), array('confirm'=>_t('Are you sure you want to delete this user?'), 'class'=>'delete-icon','id'=>'x'.$viewid));
if i have 15 rows in a database it will only show 10 and will generate a pagination (ajaxUpdate = true) for next 5. The first 10 rows has no problem with the ajaxLink because the clientscript was generated but problem is the when I move to the next page, the ajaxLink is not working because its not generated by the pagination .
any idea? thanks
An alternate method, check this post in the yii forum. So your code will become like this:
echo CHtml::link($text,
$this->createUrl('admin/deleteuser',array('id'=>$data->iduser)),
array(// for htmlOptions
'onclick'=>' {'.CHtml::ajax( array(
'beforeSend'=>'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
'success'=>"js:function(html){ alert('removed'); }")).
'return false;}',// returning false prevents the default navigation to another url on a new page
'class'=>'delete-icon',
'id'=>'x'.$viewid)
);
Your confirm is moved to jquery's ajax function's beforeSend callback. If we return false from beforeSend, the ajax call doesn't occur.
Another suggestion, you should use post variables instead of get, and also if you can, move the ajax call to a function in the index view, and just include calls to the function from the all links' onclick event.
Hope this helps.
Not fully sure, but given past experiences I think the problem is in the listview widget itself.
If the owner of the widget is a Controller, it uses renderPartial to render the item view.
Renderpartial has, as you may or may not know, a "processOutput" parameter which needs to be set to TRUE for most of the AJAX magic (its FALSE by default).
So perhaps you can try to just derive a class of the listview and add a copy in there of "renderItems()". There you would have to change it so that it calls renderPartial with the correct parameters.
In the widget Clistview, I added afterAjaxUpdate
$jsfunction = <<< EOS
js:function(){
$('.delete-icon').live('click',function(){
if(confirm('Are you sure you want to delete?'))
{
deleteUrl = $(this).attr('data-href');
jQuery.ajax({'success':function(html){ },'url':deleteUrl,'cache':false});
return false;
}
else
return false;
});
}
EOS;
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'id'=>'subscriptionDiv',
'itemView'=>'_subscription',
'afterAjaxUpdate'=>$jsfunction,
'viewData'=>array('is_user'=>$is_user,'all'=>$all),
'htmlOptions'=>($dataProvider->getData()) ? array('class'=>'table') : array('class'=>'table center'),
)
);
and in the _user just added attribute data-href
<?php echo CHtml::ajaxLink($text, $this->createUrl('admin/deletesubscription',array('id'=>$data->idsubscription)),
array('success'=>"js:function(html){ $('#tr{$viewid}').remove(); }"),
array('confirm'=>_t('Are you sure you want to unsubscribe?'),
'class'=>'delete-icon',
'id'=>'x'.$viewid,
'data-href'=>$this->createUrl('admin/deletesubscription',array('id'=>$data->idsubscription))
)); ?>
try
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_user',
'enablePagination' => true,
);
if this doesn't solve, try including the total number of records in the data provider options as -
'itemCount' => .....,