HI我想创建Alpha寻呼机搜索,搜索工作正常,但是当我点击搜索它会干扰UI,如加载标题和菜单第二次和网站开始再次显示菜单
这是 admin.php查看页面:
<?php
/* @var $this AreaController */
/* @var $model Area */
$this->breadcrumbs = array(
'Areas' => array('index'),
'Manage',
);
?>
<h1>Manage Areas</h1>
<div>
<?php
echo CHtml::ajaxLink('F', Yii::app()->createUrl('area/admin'), array('data' => array('q' => 'F'), 'update' => '#area-grid'), array());
echo CHtml::ajaxLink('E', Yii::app()->createUrl('area/admin'), array('data' => array('q' => 'E'), 'update' => '#area-grid'), array());
//echo CHtml::link('S', array('area/admin', 'q' => 'S'), array('target' => '_blank'));
?>
</div>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'area-grid',
'itemsCssClass' => 'table-bordered items',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'class' => 'editable.EditableColumn',
'name' => 'Area',
'headerHtmlOptions' => array('style' => 'width: 110px'),
'editable' => array(//esditable section
'url' => $this->createUrl('area/updateEditable', array('model' => 'Area', 'field' => 'status')),
'placement' => 'right',
)
),
array(
'class' => 'editable.EditableColumn',
'name' => 'status',
'headerHtmlOptions' => array('style' => 'width: 100px'),
'editable' => array(
'type' => 'select',
//'url' => Area::getStatusList(),
'url' => $this->createUrl('area/updateEditable', array('model' => 'Area', 'field' => 'status')),
'source' => $this->createUrl('area/getStatuses'),
'options' => array(//custom display
'display' => 'js: function(value, sourceData) {
var selected = $.grep(sourceData, function(o){ return value == o.value; }),
colors = {"Active": "green", "InActive": "red"};
$(this).text(selected[0].text).css("color", colors[value]);
}'
),
//onsave event handler
'onSave' => 'js: function(e, params) {
console && console.log("saved value: "+params.newValue);
}',
'htmlOptions' => array(
'data-username' => '$data->status'
)
)
),
),
));
?>
控制器管理员操作代码:
public function actionAdmin() {
$model = new Area('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Area']))
$model->attributes = $_GET['Area'];
$this->render('admin', array(
'model' => $model,
));
}
模型搜索功能代码:
public function search() {
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria = new CDbCriteria;
if (isset($_GET['q'])) {
$criteria->condition = 'Area like "' . $_GET["q"] . '%" ';
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
$criteria->compare('id', $this->id);
$criteria->compare('Area', $this->Area, true);
$criteria->compare('status', $this->status, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}