我到處都是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