Yii Framework Forum: Filter data in CListView and CGridView using AJAX. How? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Filter data in CListView and CGridView using AJAX. How? Rate Topic: -----

#1 User is offline   Egorka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 15-September 09
  • Location:Kaluga, Russia

Posted 20 February 2010 - 04:51 AM

Hello. I create search widget which using CHtml::ajaxSubmitButton send data in Filter action

public function actionFilter()
{
            $session=new CHttpSession;
            $session->open();
            $session['adm_area']=$_POST['re']['adm_area'];
}          


For test i save filter data in session. Then i add this data to add SearchCondition.

My List action:
public function actionList()
        {
            $this->publishJsCss();
            Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/protected/controllers/js/hover.js');
            $session=new CHttpSession;
            $session->open();
            $criteria=new CDbCriteria();
            $criteria->addSearchCondition('adm_area',$session['adm_area']);
            $dataProvider=new CActiveDataProvider('estate', array(
            'criteria'=>$criteria,
            'pagination'=>array('pageSize'=>10,),
            ));
            $this->render('estate', array('dataProvider'=>$dataProvider,));
        }


Estate view:

<?php
$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_re',
    'sortableAttributes'=>array('price'=>'price'),
    'template'=>"{summary}{sorter}{pager}{items}\n{pager}",
    'cssFile'=>false,
    'pager'=>array('header'=>'','cssFile'=>false),
    ));
    ?>



How reload CListView items using AJAX after add SearchCondition? Thank you in advance for your help.
0

#2 User is offline   Brasuca 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 05-August 10
  • Location:Belo Horizonte, Brazil

Posted 24 August 2010 - 03:33 PM

Hi, did you figure this out? Thanks!
0

#3 User is offline   FaceySpacey 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 27-October 09
  • Location:New York City

Posted 18 October 2010 - 03:42 AM

yea, filtering CListView would be very nice. What i like about CListView vs. CGridView is that listview has independent view files for each row, while gridview echos all the data out. I need to make some pretty custom rows and filter them, and looking like a plain jane table like gridview produces won't do. So I'm about to try to modify the html gridview spits out (e.g. so instead of <td> elements like divs are used). But my guess is that all the sorting/filtering/paging js all breaks.

So Basically CListView with filtering would give you the most important stuff from gridview, but with cleaner html _view files for each row/item. Would love to see ListView extended to do this right.
http://www.faceyspacey.com - I'm a Web 2.0 Development Monster.
2

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 18 October 2010 - 04:18 AM

You can achive it by creating your own ajax pager. read this post for know how.

Then you can configure your CListView for use the pager:

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_post',   // refers to the partial view named '_post'
    'pager'=>array('class'=>'myAjaxPager'),
));


0

#5 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 18 October 2010 - 05:15 AM

Hi,

i'd say the easiest way is to call the js update-function of the listview after your ajax request is completed.
By defining your ajaxSubmitButton something like this:
ajaxSubmitButton('Lets go', 'REQUEST_URL', array('success'=>'$.fn.yiiListView.update("LIST_ID");')); // Replace LIST_ID with the ID of the CListView you want to update


After the ajax call of your ajaxSubmitButton was successful (and the search data was stored inside the session) it triggers the build-in js function that updates the listview.

Regards
0

#6 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 18 January 2011 - 06:57 PM

Anybody developed an elegant solution for this yet?

Ideally what I'm after is a filter row at the top that works just like CGridView but instead of table rows we have CListView instead.
0

#7 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 January 2011 - 05:49 AM

Anyone else agree that CListView should be enhanced to include the filtering functionality, similar to CGridView? Furthermore, I think there should be an option to put the sorting filters into a dropdown.
4

#8 User is offline   because 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 01-March 11
  • Location:Russia

Posted 01 March 2011 - 02:46 AM

we can update CListView similar to CGridView. In a form we have input field. When form submitted, ajax call occured. In our list action we can get value of our field via $_GET. and then apply necessary conditions to our criteria. Sorry for my bad english )
   
$('form').submit(function(){
       $.fn.yiiListView.update('list', {
             data: $(this).serialize()
        });
         return false;
});

0

#9 User is offline   Akshay Vanjare 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 21-October 12

Posted 22 October 2012 - 04:06 AM

following link will help you to filter data in CListView using AJAX.
http://www.yiiframew...history-enable/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users