如何复制datagrid列easyui的值

时间:2014-04-22 09:24:14

标签: javascript jquery-easyui zeroclipboard

<script type="text/javascript">
    var tbIndex = undefined
    var tbData = undefined

    $('#dg').datagrid({
        onClickRow:function(rowIndex,rowData){
            tbIndex = rowIndex
            tbData = rowData
        },
        onClickCell:function(rowIndex,field,value)
        {
            if(field == 'type' || field == 'name' || field == 'card' || field == 'money')
            {
                var t = $('#dg').datagrid('selectRow',rowIndex)
                console.log($(t).html())
                ZeroClipboard.config({moviePath: "{{ URL::to('/') }}/images/ZeroClipboard.swf"})
                //copy contents()
                var client = new ZeroClipboard($('#dg').datagrid('selectRow',rowIndex));

                client.on( 'load', function(client) {
                    //alert( "movie is loaded" );
                    client.on( 'datarequested', function(client) {
                        client.setText(this.innerHTML);
                    } );

                    client.on( 'complete', function(client, args) {
                        alert("copy complete:" + args.text );
                    } );

                } );
            }

        }
    })

我现在想实现点击一列,复制一列的内容

1 个答案:

答案 0 :(得分:1)

也许你可以做类似

的事情
$('#dg').datagrid({
    onClickCell:function(rowIndex,field,value) {
         var rows = $('#dg').datagrid('getRows');
         var results = [];
         for (var i=0; i<rows.length; i++) {
             if (field == 'type') {
                results[i] = rows[i].type;
             } else if (field == 'name') {
                results[i] = rows[i].name;
             } else if (field == 'card') {
                results[i] = rows[i].card;
             } else if (field == 'money') {
                results[i] = rows[i].money;
             }
         }
    }
});

这将获得与您单击的单元格相同列的行的值。