Search Results In Tbgridview Not Working

In ContractorsController I have two functions - to get a list of users that have logged in and those that have not logged in. The resulting view gives me the correct data however I am unable to search the results.

In the ContractorsController I am getting data from a different model (User) - this is the function in Contractors Contoller:




public function actionLoginhistory() {


		$model=new User('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['User'])) {

			$model->attributes=$_GET['User'];

		}

	

		$this->render('loginlist', array(

			'model'=>$model,

			));

	}



The View for this is as follows




$this->widget('bootstrap.widgets.TbGridView', array(

    'type' => 'striped bordered condensed',

    'dataProvider' => $model->loginsearch(), 

    'filter'=>$model,

    'ajaxUpdate'=>false, 

    'enablePagination'=>true,

    'summaryText'=>'Displaying {start}-{end} of {count} results.',

    'template' => "{summary}{items}{pager}",

    'htmlOptions'=>array('style' => 'width:500px;margin-left: 130px;',),

    'columns' => array(

        array('name' => 'real_name', 'header'=> 'Trading Name','htmlOptions'=>array('width'=>'50%'),

            'type'=>'raw',

            'value' =>'CHtml::link($data->real_name, array("contractors/viewalldocuments","id"=>$data->username))',

            ),

        array('name' => 'email', 'header' => 'Email','htmlOptions'=>array('width'=>'30%')),

        array('name' => 'last_login', 'header' => 'Last Login', 'filter'=>false, 'htmlOptions'=>array('width'=>'20%'), 'value' => 'date("d-m-Y", strtotime($data->last_login))'),

    ))

);



I created a function in the User model which refers to the above dataProvider:




public function loginsearch()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		$criteria->compare('real_name',$this->real_name,true);

		$criteria->compare('username',$this->username,true);

		$criteria->compare('email',$this->email,true);

		$criteria->compare('last_login',$this->last_login,true);

		$criteria->condition = 'last_login IS NOT NULL AND user_type_id=4';




		return new CActiveDataProvider($this, array(

			'pagination' => array(

             'pageSize' => 80,

        ),

			'criteria'=>$criteria,

		));

	}



I initially get the correct data in the view however when I try to search within the results I am simply returned the results I got from the initial query - the search does not narrow down the results - I am just returned all the results from the initial query. If I change the line in the view to




'dataProvider' => $model->search(),



The search function works - however what I want is DIFFERENT search functions for different views. The search function in the User model is




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		$criteria->compare('real_name',$this->real_name,true);

		$criteria->compare('username',$this->username,true);

		$criteria->compare('email',$this->email,true);

		$criteria->compare('last_login',$this->last_login,true);




		return new CActiveDataProvider($this, array(

			'pagination' => array(

             'pageSize' => 80,

        ),

			'criteria'=>$criteria,

		));

	}



Is it possible to have different search functions in the model? Remember I am using a search function from the User model in the Contractors controller/Contractors views.

yes , you can use searches of different models in different controllers but can u tell in few words , whether filter not working i.e the correct data or some ajax problems or condition problems or using different grids on same page with same IDs or ? so we can solve one by one to get the correct result

I know you said a few words however this is really a complete explanation. This is just driving me crazy because it should be so simple.

I decided to place the following action in the UserController just to simplify things - remove different controllers and different models as I had above. So this should be really straight forward. I have in the User controller the following function




public function actionLoginhistory() {


		$model=new User();

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['User'])) {

			$model->attributes=$_GET['User'];

		}

		


		$this->render('loginlist', array(

			'model'=>$model,

			));

	}



This renders the view "loginlist.php" which in its entirety is




<?php

/* @var $this ContractorsController */

/* @var $dataProvider CActiveDataProvider */


$this->breadcrumbs=array(

	'Login History',

);

?>


<h3>Contractors Previously Logged In</h3>




<?php $this->widget('bootstrap.widgets.TbLabel', array(

    'type'=>'inverse', // 'success', 'warning', 'important', 'info' or 'inverse'

    'label'=>'NOTE: Click on Trading Name to view associated documents',

));


$this->widget('bootstrap.widgets.TbGridView', array(

    'type' => 'striped bordered condensed',

    'dataProvider' => $model->searchlogin(), 

    'filter'=>$model,

    'ajaxUpdate'=>false, 

    'enablePagination'=>true,

    'summaryText'=>'Displaying {start}-{end} of {count} results.',

    'template' => "{summary}{items}{pager}",

    'htmlOptions'=>array('style' => 'width:500px;margin-left: 130px;',),

    'columns' => array(

        array('name' => 'real_name', 'header'=> 'Trading Name','htmlOptions'=>array('width'=>'50%'),

            'type'=>'raw',

            'value' =>'CHtml::link($data->real_name, array("contractors/viewalldocuments","id"=>$data->username))',

            ),

        array('name' => 'email', 'header' => 'Email','htmlOptions'=>array('width'=>'30%')),

        array('name' => 'last_login', 'header' => 'Last Login', 'filter'=>false, 'htmlOptions'=>array('width'=>'20%'), 'value' => 'date("d-m-Y", strtotime($data->last_login))'),

    ))

);

?>



This produces the correct subset of data from the User table. Now in the model I have the following




	public function searchlogin()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		$criteria->compare('real_name', $this->real_name);

		$criteria->condition = 'last_login IS NOT NULL AND user_type_id=4';




		return new CActiveDataProvider('User', array(

			'pagination' => array(

             'pageSize' => 80,

        ),

			'criteria'=>$criteria,

		));

	}



This will produce a view where I can type in a search term in either the "Trading Name" column or the "Email" column. When I type in the search term it simply renders the same data that was produced in the initial view. The data is not filtered down by search term. I have 3 searches in the User model - the default search and 2 custom searches (one shown above for users that have a value in the last_login field and one for those that do not have a value in the last_login field of the User table). The 3 search functions I have in the User model are




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		$criteria->compare('real_name',$this->real_name,true);

		$criteria->compare('username',$this->username,true);

		$criteria->compare('email',$this->email,true);

		$criteria->compare('last_login',$this->last_login,true);




		return new CActiveDataProvider($this, array(

			'pagination' => array(

             'pageSize' => 80,

        ),

			'criteria'=>$criteria,

		));

	}


	public function searchlogin()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		$criteria->compare('real_name', $this->real_name);

		$criteria->condition = 'last_login IS NOT NULL AND user_type_id=4';




		return new CActiveDataProvider('User', array(

			'pagination' => array(

             'pageSize' => 80,

        ),

			'criteria'=>$criteria,

		));

	}


	public function searchnologin()

	{


		$criteria=new CDbCriteria;

		$criteria->compare('real_name',$this->real_name,true);

		$criteria->compare('email',$this->email,true);


		$criteria->condition = 'last_login IS NULL AND user_type_id = 4';




		return new CActiveDataProvider($this, array(

			'pagination' => array(

             'pageSize' => 80,

        ),

			'criteria'=>$criteria,

		));

	}



I do not understand why the data will not filter down when I enter a search term. The confusing part is that if I make the view have




'dataProvider' => $model->search(), 



Then obviously ALL the data in the User table is returned and when I type in a search term the data is filtered by that search term. I do not understand why my custom searches do not allow the data to be filtered. The resulting url from the query is

bump