2013-11-28 50 views
0

我到处都是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); 
}); 
/*]]>*/ 
+0

正如我看到没有其他来源的错误:你可以c&p模型的search()方法吗? – DaSourcerer

+0

添加了搜索,它只是默认生成的任何yii。 – jaime

+0

我不明白。一切都很好看。你用'$ this-> render('view',...)调用的视图是否真的是预期的视图?即它不是“查看”你想要的“索引”? – DaSourcerer

回答

0

虽然警予运行CGridView它在为CGridView正常作业的页面底部会自动生成一个jQuery复制,从浏览器的脚本也不会告诉你在视图,以便从浏览器中复制并粘贴在这里。这jQuery可能会造成一些问题。

+0

好吧,我粘贴它,它还包括jquery.yiigridview.js – jaime

0

尝试检查此使用萤火虫,并检查是否jquery工作与否。