Answer the question
In order to leave comments, you need to log in
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,
]
}
...
}
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,
]);
}
...
}
$this->widget('GridView',
[
'rowCssClassExpression' => '$data->getRowCssClass()',
'id' => 'bids-grid',
'dataProvider' => $dataProvider,
'filter' => $model,
'enablePagination' => true,
'columns' =>
[
[
'name' => 'id',
'headerHtmlOptions' =>
[
'width' => 50
],
],
]
]);
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question