将表格行复制到剪贴板-仅复制第一页 [英] Copy table rows to clipboard- copying only the first page

查看:86
本文介绍了将表格行复制到剪贴板-仅复制第一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此引用将我的表(已分页)复制到剪贴板-

I am using this reference to copy my table(paginated) to clipboard- Select a complete table with Javascript (to be copied to clipboard) But the problem I am facing here is, it is just copying the first page data. I need all the rows to be copied, irrespective of which page I am on. I am using this in an angular application. Kindly provide me a work around for this.

推荐答案

只能通过JavaScript完成.

It can be done by JavaScript only.

可以分两步完成:

第1步:使用选择命令选择要获取的表

Step 1 : Select table get using selection command

第2步:使用document.execCommand("copy");

请在下面检查:

 function selectElementContents(el) {
        var body = document.body, range, sel;
        if (document.createRange && window.getSelection) {
            range = document.createRange();
            sel = window.getSelection();
            sel.removeAllRanges();
            try {
                range.selectNodeContents(el);
                sel.addRange(range);
            } catch (e) {
                range.selectNode(el);
                sel.addRange(range);
            }
            document.execCommand("copy");

        } else if (body.createTextRange) {
            range = body.createTextRange();
            range.moveToElementText(el);
            range.select();
            range.execCommand("Copy");
        }
    }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table id="tableId">
    <thead>
        <tr><th>Heading 1</th><th>Heading 2</th></tr>
    </thead>
    <tbody>
        <tr><td>cell 1</td><td>cell 2</td></tr>
        <tr><td>cell 3</td><td>cell 4</td></tr>
    </tbody>
</table>

<input type="button" value="select table"
   onclick="selectElementContents( document.getElementById('tableId') );">

现在Ctrl+V根据您的要求粘贴剪贴板值

Now Ctrl+V paste clipboard value as per your requirement

这篇关于将表格行复制到剪贴板-仅复制第一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆