YII gridview过滤器不工作
我完全迷失在Yii gridview过滤器中。视图页面上有一个gridview,即学生/视图 以下是StudentController中的控制器:YII gridview过滤器不工作,gridview,filter,yii,Gridview,Filter,Yii,我完全迷失在Yii gridview过滤器中。视图页面上有一个gridview,即学生/视图 以下是StudentController中的控制器: /** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $this->layout = "//layouts/column1";
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id) {
$this->layout = "//layouts/column1";
$this->render('view', array(
'model' => $this->loadModel($id),
));
}
但是!我想从学时模型(而不是学生模型)在gridview中显示和过滤给定学生的学时。下面是视图文件的一部分:
<?php
$hour = new Hour();
$hour->student_id = $model->id;
$hour->time_start = $startDate;
$hour->time_end = $endDate;
?>
<?php
$this->widget('bootstrap.widgets.BsGridView', array(
'id' => 'hour-grid',
// 'dataProvider' => $hourModel->StudentHoursSearch($model->id),
'dataProvider' => $hour->search(),
'filter'=>$hour,
'columns' => array(
//'student_id',
array(
'name' => 'instructor_id',
'value' => '$data->instructor->name',
'filter'=>CHtml::listData(Instructor::model()->findAll(), 'id', 'name'),
),
array(
'name' => 'time_start',
'value' => 'date("Y-m-d", strtotime($data->time_start))."<br />".date("H:i", strtotime($data->time_start))',
'type' => 'html',
),
'hour_topic',
array(
'name' => 'type',
'type' => 'html',
'value' => '$data->ticket_lease == "lease" ? $data->getTypeLabel() : ($data->ticket_lease == "ticket" ? $data->getTypeLabel() . " (jegy)" : ($data->cancel_type == 3 ? $data->getTypeLabel() . "<br />DK lemondás" : (date("Y-m-d", strtotime($data->time_start)) == date("Y-m-d") ? $data->getTypeLabel() : $data->getTypeLabel() . " <br/>Nincs lezárva")))',
'filter' => Hour::$type_labels
),
/* array(
'name' => 'hour_topic',
'value'=>'$data->hour_topic'
), */
),
'rowCssClassExpression' => '
$data->cancel_type == 3 ? "drumkiller_cancel" : ($data->type === "presenter" ? "student_presenter" : ($data->type === "training" ? "student_training" : "student_practice"))
',
));
?>
也许您需要从控制器而不是视图中传入Hour类,然后确保从gridview将触发的GET参数中设置属性
也许是这样的:
public function actionView($id) {
$this->layout = "//layouts/column1";
$hour = new Hour('search');
$hour->unsetAttributes(); // clear any default values
if (isset($_GET['Hour'])) {
$hour->attributes = $_GET['Hour'];
}
$this->render('view', array(
'model' => $this->loadModel($id),
'hour' => $hour,
));
}
谢谢它并没有解决我的问题。我认为问题在于ajax更新后没有重新初始化。如果我使用过滤器(例如,选择小时类型或开始日期),则表将刷新,但我不能使用其他过滤器。我希望我能清楚地描述一下,我确实看到您正在使用引导程序小部件。我不小心过早地按了enter键,下面是我的评论:我确实看到您正在使用“bootstrap.widgets.BsGridView”小部件。对不起,我不熟悉那个。我会尝试使用默认的yiicgridview小部件:“zii.widgets.grid.CGridView”。您可以尝试通过Gii工具生成代码,以使过滤在默认情况下工作,然后从那里修改它。如果我不能提供进一步的帮助,我很抱歉。谢谢我按照你的建议试了一下。
public function actionView($id) {
$this->layout = "//layouts/column1";
$hour = new Hour('search');
$hour->unsetAttributes(); // clear any default values
if (isset($_GET['Hour'])) {
$hour->attributes = $_GET['Hour'];
}
$this->render('view', array(
'model' => $this->loadModel($id),
'hour' => $hour,
));
}