Jump to content
Larry Ullman's Book Forums

Filtering In Tbgridview Not Working

Recommended Posts

The problem I have is that I am returning a subset of data from the User table to a view. Using TbGridView I should be able to type in a search term and this data should be filtered by my search term however the data is not filtered. The same data is simply retuned. The filtering is not working.

I have an action in my User controller to show a list of users that have previously logged in. The action is

public function actionLoginhistory() {

$model=new User('searchlogin');
$model->unsetAttributes();  // clear any default values
if(isset($_GET['User'])) {

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

This returns the correct data set to my view. The problem is that when I try to filter the data by typing in a search term in the Trading Name column or Email column the same data set is returned. The view code is:

$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'striped bordered condensed',
'dataProvider' => $model->searchlogin(), 
'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%'),
        '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))'),

The data set returned is from the User model - the code for this is:

public function searchlogin()

            $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,

If I change my view code to use the standard search function then every user in the user table is returned and the data will filter down by search term. So if I change one line in the view to

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

Then every user is returned but the data will filter by search term. The standard search function in the model this refers to in the User Model is

public function search()

            $criteria=new CDbCriteria;

            return new CActiveDataProvider($this, array(
                    'pagination' => array(
         'pageSize' => 80,

This should be really straight forward and simple. You should be able to have multiple search functions in a Model - I have been looking at this for days and I just cannot resolve the problem. I would appreciate any help. When I type in the search term the code generates what I would expect the url to be



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...