Yii中Cgridview选中行列值

Ayy*_*r G 2 yii

在此输入图像描述

使用下面的代码我获取所有“名称”列值

$.fn.yiiGridView.getColumn("CGridViewUser",1).text();
Run Code Online (Sandbox Code Playgroud)

如果我想获取选定行的“名称”列值(如图所示),如何实现?

Hea*_*man 5

首先向您的 GridView 添加一个 ID。

   <?php
   $this->widget('zii.widgets.grid.CGridView', array
   (
        'dataProvider'=>$dataProvider,
        'htmlOptions'=>array('id'=>'MyID'), //MyID is an ID to grid wrapper
         ........
         ........
Run Code Online (Sandbox Code Playgroud)

现在,jQuery

       $("#MyID table tbody tr").click(function()
       {
            $this=$(this);
            var firstColVal= $this.find('td:first-child').text();
            var secondColVal= $this.find('td:nth-child(2)').text();
            var lastColVal= $this.find('td:last-child').text();
            alert(firstColVal);
       });
Run Code Online (Sandbox Code Playgroud)

它会起作用的。