E
E
EVOSandru62015-01-03 11:57:20
Yii
EVOSandru6, 2015-01-03 11:57:20

Why filter and search in CGridView may not work in yii1?

Good afternoon,
There is a table that has many fields, I noticed that filter (entering values ​​in the input at the top of the columns) and advancedSearch do not work for me .
The thinking circle is spinning, but nothing happens, by the method of elimination I chopped off the rules for searching to one field: id . And all the same the filter does not work, as well as search.
Model:

class Bids extends ActiveRecord
{
...
public function rules()
  {
    return
      [
        [
          'id', 'safe', 'on'=>'search'
                                ]
                       ]}


public function search()
  {
    $criteria = new CDbCriteria;
    $criteria->compare('t.id',			$this->id);

return new CActiveDataProvider($this,
      [
        'criteria' => $criteria,
                        ]
  
  }

...
}

Controller:
class BidsController extends BackendController
{
...
  public function actionIndex()
  {
    $model			=	new Bids('search');
    $request 		= 	Yii::app()->request->getParam('Bids');
    $model->unsetAttributes();
    $dataProvider 	= $model->search();
    if(isset($request))
      $model->attributes = $request;
    $this->render('admin',
    [
      'model'			=>	$model,
      'dataProvider'	=>	$dataProvider,
    ]);
  }
...
}

Performance:
$this->widget('GridView',
    [

        'rowCssClassExpression' =>  '$data->getRowCssClass()',
        'id'                    =>  'bids-grid',
        'dataProvider'          =>  $dataProvider,
        'filter'                =>  $model,
        'enablePagination'      =>  true,
        'columns'       =>
            [
                [
                    'name'                  =>      'id',
                    'headerHtmlOptions'     =>
                    [
                        'width' => 50
                    ],
                ],
]
    ]);

What I did not foresee why the filter does not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2015-01-03
@EVOSandru6

You left only one field to filter id and wonder why the others (remote ones) don't work.
In addition, clear all attributes, then form the data provider for them (empty), then enter the request data into the model.
In general, your execution sequence is lame, very

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question