jquery - Yii:CGridView 上 AJAX 操作的动态更新 ID

标签 jquery ajax grid widget yii

我正在使用 Yii 1.1 来实现主详细信息订单-订单-详细信息网格 到目前为止我得到了他的: enter image description here - 基本上,当我单击详细信息图标(左侧图标)时 - 它会使用 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' => 数组( '类型' => '发布', '更新'=>'#id_view', ),

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

也许我可以直接使用 Jquery,而不用使 CGrid 的选项变得复杂?

最佳答案

我想你想要这个。(将 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',
            ),
        ),
    )); ?>

关于jquery - Yii:CGridView 上 AJAX 操作的动态更新 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10515456/

相关文章:

javascript - paper.js 直接使用 JS - 如何使用 .getDistance 函数?

javascript - 在 jQuery 中在窗口滚动上运行一次函数

javascript - 在 console.log 中立即出现奇怪的行为错误

javascript - 如何使用 AJAX 切换数据库中的 bool 列?

javascript - 通过 AJAX 上传图片 - 如何将文件名传递给服务器?

XAML:我可以按名称引用网格行或列吗?

xaml - Xamarin Grid 不会均匀拆分

javascript - 动态创建列表并在每个新创建的元素中添加 HTML 标签

javascript - AJAX 聊天提交仅适用于 $(document).keypress()

c# - 如何创建具有相对宽度值的动态 ColumnDefinitions?