1

我有一个使用 CGridView 的网格,当我尝试更新它时,我会收到此错误。尝试一种方法来解决这个问题很长时间,但仍然无法让它发挥作用。我不确定我错过了什么。

以下是我用来在发生按钮单击时强制刷新网格的方法。

$('#sessions .refreshdata').live('click', function(e) {
   e.preventDefault();
   $.fn.yiiGridView.update('sessions-grid');
}
);

错误来了,

TypeError: settings is undefined

$grid.addClass(settings.loadingClass);

我不知道从哪里触发。

在此处输入图像描述

编辑1,

我尝试将进程输出设置为 true,然后它可以工作,但它与我的 UI 和同一页面中的其他需要的脚本混淆了。

$this->getController()->renderPartial('sessionGrid', $params, false, true);

我开始获取 yii 的默认 gridview 及其样式。困惑为什么会发生这种情况。

排序在同一个网格中也不起作用。当我单击列名的排序链接时,它会刷新页面并将我带到另一个页面。所以 Ajax 在这种情况下完全不起作用。

编辑2,

下面的方式也可以按照 ANSWER 1 中的建议进行工作

console.log('came in');
e.preventDefault();
$.fn.yiiGridView({ 'ajaxUpdate':['sessions-grid'] }); 
console.log('came out');

如何强制此网格刷新或更新?

编辑 3,

当我使用正常方式时,jquery.yiigridview.js 出现错误。设置未定义 - 第 203 行.. $grid.addClass(settings.loadingClass);

return this.each(function () {
var $form,
$grid = $(this),
id = $grid.attr('id'),
settings = gridSettings[id];
$grid.addClass(settings.loadingClass); 

编辑 4,我在下面复制 cgridview 代码和操作。

<?php TK::registerCssFile('grid');?>
<div id="sessions">
<h4><?php echo Yii::t('activity', (isset($model->activity->name) ? $model->activity->name . ' Sessions'  : 'Sessions')) ?></h4>
<?php $this->beginContent('application.views.templates.form', array('options'=>array('id'=>'sessions-form'))); ?>
<?php echo CHtml::hiddenField('activities_id', $model->activities_id); ?>
<?php echo CHtml::hiddenField('source', $source); ?>
<?php
$this->widget('application.components.SGridView', array(
   'id'=>'sessions-grid',
   'dataProvider'=>$model->search(),
   'filter'=>$model,
   'emptyText'=>(!empty($model->activities_id)) ? 'No results found.' : 'Please select activity from top grid.',
   'showNew'=>(!empty($model->activities_id) &&  Yii::app()->user->checkAccess("piActivitySessionsCreate") && $model->activity->source === 'iJOB') ? true : false,
   'newButtonCss'=>'new dialog-link-session',
   'createUrl'=>Yii::app()->controller->createUrl("/activities/default/sessionCreate", array("activities_id"=>$model->activities_id)),
   //'showExport'=>true,
   'columns'=>array(
      /*
      array('type'=>'raw',
         'value'=>'CHtml::hiddenField("ActivitySession[$data->id]", false, array(\'value\'=>$data->id))',
         'htmlOptions'=>array('style'=>'width:0%;'),
         'headerHtmlOptions'=>array('style'=>'width:0%;')),
      */      
      array('name'=>'site_id',
         //'value'=>'CHtml::link($data->sites->code, "#", array("title"=>$data->sites->name))',
         //'value'=>'CHtml::label($data->sites->code, null, array("title"=>$data->sites->name))',
         'value'=>'$data->sites!=null ? CHtml::tag("div", array("title"=>$data->sites->name), $data->sites->code) : ""',
         'type'=>'raw',
         'htmlOptions'=>array('style'=>'width:16%;'),
         'headerHtmlOptions'=>array('style'=>'width:16%;')),
      array('name'=>'location',
         'htmlOptions'=>array('style'=>'width:30%;'),
         'headerHtmlOptions'=>array('style'=>'width:30%;')),
      array('name'=>'start_time',
         'value'=>'Yii::app()->dateFormatter->formatDateTime($data->start_time, "medium", "short")',
         'htmlOptions'=>array('style'=>'width:15%;'),
         'headerHtmlOptions'=>array('style'=>'width:15%;')),
      array('name'=>'end_time',
         'value'=>'Yii::app()->dateFormatter->formatDateTime($data->end_time, "medium", "short")',
         'htmlOptions'=>array('style'=>'width:15%;'),
         'headerHtmlOptions'=>array('style'=>'width:15%;')),
      /*
      array('name'=>'max_positions',
         'htmlOptions'=>array('style'=>'width:6%;'),
         'headerHtmlOptions'=>array('style'=>'width:6%;')),
      */
      array('name'=>'closed',
         'value'=>'$data->closed == "1" ? Yii::t("activity", "Yes") : Yii::t("activity", "No")',
         'filter'=>array("0"=>Yii::t("activity", "No"), "1"=>Yii::t("activity", "Yes")),
         'htmlOptions'=>array('style'=>'width:6%;text-align:left;'),
         'headerHtmlOptions'=>array('style'=>'width:6%;')),
      array('name'=>'registered',
         'type'=>'raw',
         'value'=>'$data->registeredCount . \'/\' . $data->max_positions',
         'filter'=>false,
         'sortable'=>true,
         'htmlOptions'=>array('style'=>'width:8%;text-align:right;padding-right:15px'),
         'headerHtmlOptions'=>array('style'=>'width:8%;')),
      array('class'=>'CButtonColumn',
         'template'=>'{users} {view} {update} {delete}',
         'header'=>Yii::t("activity","Actions"),
         'headerHtmlOptions'=>array('style'=>'width:10%;'),
         'htmlOptions'=>array('style'=>'width:10%;'),
         'buttons'=>array(
            'users'=>array(
               'visible'=>'(Yii::app()->user->checkAccess("piActivityJobseekerRead") || Yii::app()->user->checkAccess("piActivityJobseekerUpdate")) ? true : false',
               'url'=>'Yii::app()->controller->createUrl("/activities/participants/index", array("session_id"=>$data->id))',
               'imageUrl'=>Yii::app()->request->baseUrl.'/images/base/users.png',               
               'options'=>array(
                  //'class'=>'users dialog-link-session',
                  'title'=>Yii::t('activity', 'Participants'),
               ),
            ),
            'view'=>array(
               'visible'=>'(Yii::app()->user->checkAccess("piActivitySessionsRead") && 
                  !Yii::app()->user->checkAccess("piActivitySessionsUpdate") && $data->activity->source === "iJOB") ||
                  ($data->activity->source === "ESS") ? true : false',
               'url'=>'Yii::app()->controller->createUrl("/activities/default/sessionView", array("id"=>$data->id))',
               'options'=>array('class'=>'view dialog-link-session'),
            ),
            'update'=>array(
               'visible'=>'(Yii::app()->user->checkAccess("piActivitySessionsUpdate") && $data->activity->source === "iJOB") ? true : false',
               'url'=>'Yii::app()->controller->createUrl("/activities/default/sessionUpdate", array("id"=>$data->id))',
               'options'=>array('class'=>'update dialog-link-session'),
            ),
            'delete'=>array(
               'visible'=>'(Yii::app()->user->checkAccess("piActivitySessionsDelete") && $data->activity->source === "iJOB") ? true : false',
               'url'=>'Yii::app()->controller->createUrl("/activities/default/sessionDelete", array("id"=>$data->id))',
               'options'=>array('class'=>'delete dialog-link-session'),
            ),
         ),
      ),
      array('type'=>'raw',
         'value'=>'$data->registeredCount',
         'htmlOptions'=>array('style'=>'display:none;'),
         'headerHtmlOptions'=>array('style'=>'display:none;'),
      ),
   ),
));
?>
<?php $this->endContent(); ?>
</div>
<style type="text/css">
.grid-view-body
{
    height: 170px;
}
</style>

并在行动中......

public function run()
   {
      Yii::app()->clientScript->scriptMap['*.js'] = false;
      $activities_id = (TK::get('activities_id') ? TK::get('activities_id') : (TK::post('activities_id') ? TK::post('activities_id') : 0));
      $source = (TK::get('source') ? TK::get('source') : (TK::post('source') ? TK::post('source') : 'iJOB'));
      
      if ($activities_id === null)
        throw new CHttpException(500, Yii::t('activity', 'The requested activity does not exist.'));
      
      $model = new ActivitySession('search');
      $model->unsetAttributes();
      $model->activities_id = $activities_id;
      $model->closed = null;     
      
      if (isset($_GET['ActivitySession']))
         $model->attributes = $_GET['ActivitySession'];
         
      $params = array('model'=>$model, 'source'=>$source);
      
      if (Yii::app()->request->isAjaxRequest)
         $this->getController()->renderPartial('sessionGrid', $params, false, true);
      else
         $this->getController()->renderPartial('sessionGrid', $params, false, true);
   }

然后我有如下的gridview以及刷新按钮......

在此处输入图像描述

使 porcessedOutput = true 后,刷新开始工作,但每次它增加一......所以现在刷新发生多次......下面是它现在发生 3 次的捕获。在此处输入图像描述

我怎样才能阻止这种令人耳目一新的多次发生是我的问题。

4

1 回答 1

1

只是一个想法,试试

$('#sessions .refreshdata').live('click', function(e) {
   e.preventDefault();
   $.fn.yiiGridView({ 'ajaxUpdate':['sessions-grid']  });
);

希望这可以帮助

你能在这里显示cgridview吗?问题可能是你如何设置它

于 2013-09-10T14:38:28.820 回答