【问题标题】:Cgridview selected row column value in YiiYii中的Cgridview选择行列值
【发布时间】:2013-12-25 07:31:01
【问题描述】:

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

$.fn.yiiGridView.getColumn("CGridViewUser",1).text();

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

【问题讨论】:

    标签: yii


    【解决方案1】:

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

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

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

    它会起作用的。

    【讨论】:

    • 太棒了!!!从您的代码中获得价值...有另一个问题必须在表单的文本框中设置获得的值,您能建议怎么做吗?
    • 在表单中添加一个选择器 例如:我提供了一个 ID &lt;input id='anID' type...。现在$("#anID").val(secondColVal);
    • 是的,它的工作原理!我想在文本框中显示名称列,但在数据库中我必须保存 ID(见附图)
    • 不给出列号,是否可以给出列名?
    猜你喜欢
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    相关资源
    最近更新 更多