【问题标题】:Yii:Dynamic update ID for AJAX action on CGridViewYii:CGridView 上 AJAX 操作的动态更新 ID
【发布时间】:2012-05-09 11:48:20
【问题描述】:

我正在使用 Yii 1.1 来实现主详细信息 order-order-details 网格 到目前为止,我得到了他的: - 基本上当我单击详细信息图标(左图标)时 - 它使用 ajax 加载带有详细信息的详细信息网格(我为此使用了一个名为 EAjaxLinkColumn 的组件 - 默认情况下,链接列不支持 ajax)

这是我的代码:

<?php     $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'main-orders-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(

    array (
    'class'=>'EAjaxLinkColumn',
    'header'=>'Details',
    'url'=>Yii::app()->createUrl('mainOrdersDetails/detailview'),
    'imageUrl'=>Yii::app()->request->baseUrl.'/images/zoom_in.png',

          //linkAjaxOptions and linkAjaxOptionsExpression are merged together, so only put the ones
          //that actually need to be evaluated in the latter
          'linkAjaxOptions' => array(
             'type' => 'POST',
             /*'dataType' => 'json',       */
             'update'=>'#id_view',
          ),
          //In this expression, the variable $row the row number (zero-based); 
          //$data the data model for the row; and $this the column object.
          'linkAjaxOptionsExpression' => array(
             'data' => array(
               'id' => '$data->id' //note that $data->id is an expression so must be quoted
             ),
          ),

    ),    

            'id',   
            'storageF.name',
            'date_added',
            'order_number',
            'expected_ship_date',
            'shipped_date',
            'shipping_costs',
            'personF.user',
            'date_to_pay',
            'paid_integraly',
            'paid_partialy',        
            array(
                'class'=>'CButtonColumn',
            ),
        ),
    )); ?>

我想要在每一行下方加载它的详细信息。好吧,我不知道该怎么做..因为 CGridView 小部件对于像我这样在 Yii 的初学者来说非常奇怪 现在它总是加载到同一个 div .. 注意

'linkAjaxOptions' => 数组( '类型' => 'POST', '更新'=>'#id_view', ),

首先更新选项是静态的。我想使用 ID #id_view_1 #id_view_2 然后以某种方式在每个主行下方插入那些空行

也许我可以直接使用 Jquery 而不会使 CGrid 的选项复杂化?

【问题讨论】:

  • 这是什么#id_view?是 CListView 吗?
  • 是一个简单的 div,另一个 CGrid 从 ajax 加载

标签: jquery ajax grid widget yii


【解决方案1】:

我想你想要这个。(将 update 属性从 linkAjaxOptions 移动到 linkAjaxOptions,就像在 linkAjaxOptions 中一样,我们可以使用特殊变量 $data 和 $row

<?php     $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'main-orders-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(

    array (
    'class'=>'EAjaxLinkColumn',
    'header'=>'Details',
    'url'=>Yii::app()->createUrl('mainOrdersDetails/detailview'),
    'imageUrl'=>Yii::app()->request->baseUrl.'/images/zoom_in.png',

          //linkAjaxOptions and linkAjaxOptionsExpression are merged together, so only put the ones
          //that actually need to be evaluated in the latter
          'linkAjaxOptions' => array(
             'type' => 'POST',
             /*'dataType' => 'json',       */
          ),
          //In this expression, the variable $row the row number (zero-based); 
          //$data the data model for the row; and $this the column object.
          'linkAjaxOptionsExpression' => array(
             'data' => array(
               'id' => '$data->id' //note that $data->id is an expression so must be quoted
             ),

             'update'=>'\'#id_view_\'.$data->id',//or you can use '\'#id_view_\'.$row'; according to your needs
          ),

    ),    

            'id',   
            'storageF.name',
            'date_added',
            'order_number',
            'expected_ship_date',
            'shipped_date',
            'shipping_costs',
            'personF.user',
            'date_to_pay',
            'paid_integraly',
            'paid_partialy',        
            array(
                'class'=>'CButtonColumn',
            ),
        ),
    )); ?>

【讨论】:

  • 将“更新”参数移动到 linkAjaxOptionsExpression 会产生错误。解析错误:语法错误,/Applications/XAMPP/xamppfiles/htdocs/project/framework/base/CComponent.php 中的意外 $end (607) : eval()'d 代码在第 1 行
  • 哦,这是有道理的 :D 这就是为什么 eval 不起作用.. 它需要转义 :D 。如果我不使用 return 关键字,它会起作用 :D 超级感谢 :D 。任何想法我怎样才能在网格的行之间渗透那些额外的#id_view_1 #id_view_2 ...等?所以我可以填充内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 1970-01-01
  • 2011-12-08
  • 1970-01-01
  • 2018-04-11
相关资源
最近更新 更多