我到处都是Google搜索,我只是看不到我还缺少了什么?顶部的过滤器没有做任何事情。我认为这是来自crud的默认值,不确定。我还有什么在这里错过?cgridview根本无法过滤
控制器:
$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);
});
/*]]>*/
正如我看到没有其他来源的错误:你可以c&p模型的search()方法吗? – DaSourcerer
添加了搜索,它只是默认生成的任何yii。 – jaime
我不明白。一切都很好看。你用'$ this-> render('view',...)调用的视图是否真的是预期的视图?即它不是“查看”你想要的“索引”? – DaSourcerer