我到处搜索,我只是看不出我还缺少什么?顶部的过滤器不做任何事情。我认为这是crud的默认值,不确定。我在这里还缺少什么呢?
控制器:
$model=new Product('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Product']))
$model->attributes=$_GET['Product'];
$this->render('view',array(
'model'=>$model,
));
模型规则:
array('product_id, product_name,product_price, product_status, 'safe', 'on'=>'search'),
并查看:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'product_id',
'product_name',
'product_price',
'product_status',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
模型搜索,几乎是默认的
$criteria=new CDbCriteria;
$criteria->compare('product_id',$this->product_id);
$criteria->compare('product_name',$this->product_name);
$criteria->compare('product_price',$this->product_price);
$criteria->compare('product_status',$this->product_status);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
JS
jQuery(function($) {
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#product-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
jQuery(document).on('click','#product-grid a.delete',function() {
if(!confirm('Are you sure you want to delete this item?')) return false;
var th = this,
afterDelete = function(){};
jQuery('#product-grid').yiiGridView('update', {
type: 'POST',
url: jQuery(this).attr('href'),
success: function(data) {
jQuery('#product-grid').yiiGridView('update');
afterDelete(th, true, data);
},
error: function(XHR) {
return afterDelete(th, false, XHR);
}
});
return false;
});
jQuery('#product-grid').yiiGridView({'ajaxUpdate':['product-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'enableHistory':false,'updateSelector':'{page}, {sort}','filterSelector':'{filter}','pageVar':'Product_page'});
App.setMainPage(true);
App.init();
App.setTableDetails(jsonDashboard);
});
/*]]>*/
答案 0 :(得分:0)
在yii中运行CGridView时,它会在页面底部自动生成一个jquery,以便正确处理CGridView副本,该浏览器中的脚本不会在视图中显示,因此请将其从浏览器中复制并粘贴到此处。那个jquery可能会出问题。
答案 1 :(得分:0)
尝试使用firebug检查它并检查jquery是否正常工作。