Search code examples
yiiyii-components

CGridView limited to 90 records


Yii 1.1.14

When my table holds more than 90 records, CGridView will fail to load the newest records. When I delete some records, and bring the total below 90, it will again show me the most recent records.

  • How do I get CGridView to show the newest records?

My model::search() is almost as out of the box. (Only change: sort descending).

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',
                    ),
    ));
}

And here is my view:

<?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',
                        ),
                    ),
    ),
),
)); ?>

Solution

  • Your question is very confusing as you are not describing the problem properly. What are the newest records? do you mean that the list is shown, records are added behind the scene and when navigating through the list does not show the just added records?

    The problem might be because the queries are cached. You can put a condition like

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

    that would make every query unique so your query will never be cached.