CGridView限制为90条记录

时间:2014-02-25 11:59:58

标签: yii yii-components

Yii 1.1.14

当我的表包含超过90条记录时,CGridView将无法加载最新记录。当我删除一些记录并将总数降至90以下时,它将再次向我显示最新的记录。

  • 如何让CGridView显示最新记录?

我的模型:: search()几乎是开箱即用的。 (只改变:降序排序)。

public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('xpl',$this->xpl,true);
    $criteria->compare('phpClass',$this->phpClass,true);
    $criteria->compare('line',$this->line);
    $criteria->compare('function',$this->function,true);
    $criteria->compare('usr',$this->usr,true);
    $criteria->compare('guessedName',$this->guessedName,true);
    $criteria->compare('email',$this->email,true);
    $criteria->compare('cls',$this->cls);
    $criteria->compare('vis',$this->vis);
    $criteria->compare('cet',$this->cet,true);
    $criteria->compare('trace',$this->trace,true);
    $criteria->compare('iconID',$this->iconID);
    $criteria->compare('albumID',$this->albumID);
    $criteria->compare('record_created',$this->record_created,true);
    $criteria->compare('timestamp',$this->timestamp);
    $criteria->compare('vrs',$this->vrs,true);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
                    'sort'=>array(
                        'defaultOrder'=>'id DESC',
                    ),
    ));
}

以下是我的观点:

<?php

Yii::app()->ClientScript->registerScriptFile($this->assetsBase.'/js/plug.note.js', CClientScript::POS_END);
Yii::app()->clientScript->registerCssFile($this->assetsBase.'/css/x0.css');
Yii::app()->ClientScript->registerCssFile($this->assetsBase.'/fontello/css/fontello.css', 'screen');
Yii::app()->ClientScript->registerCssFile($this->assetsBase.'/fontello/css/animation.css', 'screen');
$this->breadcrumbs=array(
'Ifas'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Ifa', 'url'=>array('index')),
array('label'=>'Create Ifa', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#ifa-grid').yiiGridView('update', {
    data: $(this).serialize()
});
return false;
});
// set up polling at interval
$(function() {
    $.fn.note('poll');
});
");
?>
<style>
i.icon-tag, i.icon-wrench {font-size: 18px;}
</style>
<div style="float: left; margin-right: 10px;">Notes (Family Archives)</div>
<div style="float:right; margin-left: 10px;">
<div class="ERR" style="float:left;">
    <input type="radio" name="cls" id="cls3" onclick="$('.row input[name=\'Ifa[cls]\']').val(3).submit();">
    <label for="cls3">error</label>
</div>
<div class="WAR" style="float:left;">
    <input type="radio" name="cls" id="cls2" onclick="$('.row input[name=\'Ifa[cls]\']').val(2).submit();">
    <label for="cls2">warning</label>
</div>
<div class="INF" style="float:left;">
    <input type="radio" name="cls" id="cls1" onclick="$('.row input[name=\'Ifa[cls]\']').val(1).submit();">
    <label for="cls1">info</label> 
</div>
<div class="DBG" style="float:left;">
    <input type="radio" name="cls" id="cls0" onclick="$('.row input[name=\'Ifa[cls]\']').val(0).submit();">
    <label for="cls0">debug</label>
</div>
<div class="" style="float:left; background-color:#CCCCCC;">
    <input type="radio" name="cls" id="cls" onclick="$('.row input[name=\'Ifa[cls]\']').val('').submit();">
    <label for="cls">all</label>
</div>
</div>
<div style="float:right; background-color:#CCCCCC; margin-left: 10px;">
    <input type="radio" name="vis" id="vis1" onclick="$('.row input[name=\'Ifa[vis]\']').val(1).submit();" checked="checked">
    <label for="vis10">visible</label>  
    <input type="radio" name="vis" id="vis0" onclick="$('.row input[name=\'Ifa[vis]\']').val(0).submit();">
    <label for="vis0">invisible</label>    
    <input type="radio" name="vis" id="vis" onclick="$('.row input[name=\'Ifa[vis]\']').val('').submit();">
    <label for="vis">both</label>  
</div>
<div style="float:right; background-color:#CCCCCC; margin-left: 10px;">
    <input type="checkbox" id="poll" onclick="" checked="checked">
    <label for="poll">polling (<span id="lag">?</span> s)</label>  
</div>
<div style="float:right; background-color:#CCCCCC; margin-left: 10px;        "onclick="$.fn.note('max_id')">
max id <span id="max-id">?</span>
</div>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button', 'style' => 'float:left; font-size: 10px;')); ?>
<div style="clear:both"></div>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ifa-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
    'rowCssClassExpression' => '$data->getRowCssClass()',
'columns'=>array(
    'id',
    'xpl',
    'phpClass',
    'line',
    'function',
    'usr',
    'guessedName',
    'email',
    array(
                'name' => 'cls',
                'visible' => false
            ),
    array(
                'name' => 'vis',
                'visible' => false
            ),
    //'cet',
    //'trace',
    'iconID',
    'albumID',
    'record_created',
    //'timestamp',
    'vrs',
    array(
        'class'=>'CButtonColumn',
                    'template'=>'{view}{delete}{cet}{trace}',
                    'buttons'=>array
                    (
                        'delete' => array
                        (
                            'click'=>"function(){
                                $(this).note('update', {'vis': 0}).note('remove row');
                                return false;}",
                            'url'=>'"#"',
                            'visible'=> '$data->vis > 0',
                        ),
                        'cet' => array
                        (
                            'label'=>'<i class="icon-tag"></i>',
                            'click'=>"function(){
                                $(this).note('modal cet');
                                return false;}",
                            'url'=>'"#"',
                        ),
                        'trace' => array
                        (
                            'label'=>'<i class="icon-wrench"></i>',
                            'click'=>"function(){
                                $(this).note('modal trace');
                                return false;}",
                            'url'=>'"#"',
                            'visible'=> 'strlen($data->trace) > 0',
                        ),
                    ),
    ),
),
)); ?>

2 个答案:

答案 0 :(得分:1)

将分页设置为false以显示所有记录

return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
        'pagination'=>false,
                    'sort'=>array(
                        'defaultOrder'=>'id DESC',
                    ),
    ));

要仅显示新记录,这就像在电子邮件中显示未读消息一样。因此,在表中添加新字段为“is_read”,并在插入时为每条记录设置为0.

然后,一旦记录读取(第一个视图),您可以将“is_read”设置为1。

在gridview标准中,添加条件以显示新记录“is_read = 0”

答案 1 :(得分:1)

您的问题非常混乱,因为您没有正确描述问题。什么是最新记录?你的意思是显示列表,在场景后面添加记录,当浏览列表时没有显示刚刚添加的记录?

问题可能是因为查询被缓存了。您可以设置类似

的条件
return array(
            'condition'=>"1<='".time()."'",
        );

这将使每个查询都是唯一的,因此您的查询永远不会被缓存。