Sorting and Pagination does not work after I build a custom keyword search that is build using relational tables

(Riesebergr) #1

I recently started to build a custom keyword search using Yii 1.1.x

The search works 100%. But as soon as I sort the columns and use pagination in the admin view the search gets lost and all results are shown. So with otherwords it’s not filtering so that only the search results show. Somehow it resets it.

In my controller my code looks as follows



    		//Table1 Columns



    		//Table 2 Columns



    		//building the Keywords

    		$keywords = explode(' ',$_REQUEST['search']);


    		foreach($keywords as $key){









    		$condition = substr($condition1,0,-1) . " OR ".substr($condition2,1);

    		$condition = str_replace('AND','OR',$condition);



    $dataProvider=new CActiveDataProvider('Messages', array(







    					'joinType'=>'LEFT JOIN',








    			'dataProvider'=>$dataProvider,'keywords'=>implode(' ',$keywords),'sort'=>$sort


and my view looks like this

$this->widget('zii.widgets.grid.CGridView', array(





















    			'template'=>'{view} {delete}',







I really do not know what do do anymore since I’m terribly lost, any help will be hihsly appreciated

(Francois Gannaz) #2

Are you using AJAX? By default, the CGridView widget is in AJAX and it causes you to loose your search parameters in some cases (especially when navigating through the browser history).

You should try to disable it and see if your problem persists. In your view, make the search form visible, remove the javascript and add to your CGridView:

	'ajaxUpdate' => false

I attach a full view that has a trigger for AJAX. If the cause of your problem isn’t in this, good luck!

(Riesebergr) #3

I’ll check this out, looks promising

(Riesebergr) #4

Okey I managed to find out what the problem is here, it’s not sending the search values through to the next page using if I save the search values in a session the pagination and sorting works but this is not probably not the right way.

Maybe setData has something to do with this


$dataProvider=new CActiveDataProvider('Messages', array(





					'condition'=>'user_id='.Yii::app()->user->u_id.' '.$condition,





$dataProvider->setData(<img src='' class='bbc_emoticon' alt='???' />?);

(Luoshiben) #5

I solved the problem by storing my criteria and sort objects in the session after they were set. Then, if the action method was called via ajax request, I reloaded them from the session before rendering the dataprovider. Here’s the forum post: Good luck!

(Riesebergr) #6

Thanx, I also did it this way and it works!!