0

I'm trying to copy the contents of the table ignoring t he header/title row to clipboard exactly the same as if you was to select it manually and copy.

I found a thread to select Select a complete table with Javascript (to be copied to clipboard) but that selects the entire table, I want to ignore the header/title row and I don't really want to "select" just copy.

<table>
    <tbody>
        <tr>
            <th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th>
        </tr>
        <tr class="user">
            <td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td>
        </tr>
        <tr class="user">
            <td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td>
        </tr>
    </tbody>
</table>

Cliboard contents should be:

test    test    test    test    test    test    test    test    test    test    test    test
test    test    test    test    test    test    test    test    test    test    test    test

Attempt to actually find the values:

    $('.CopyEntries').click(function () {
        $('tbody tr').each(function(){
            $(this).find('td').each(function(){
                console.log($(this).val());
            })
        })
    });
Community
  • 1
  • 1
Dennis Sylvian
  • 967
  • 1
  • 9
  • 31
  • Pretty straightforward. Loop over all the `tr` children of the table. For each `tr`, loop over all its `td` children, appending `innerText + '\t'` for each one to a string variable. At the end of each row append `'\n'`. What exactly are you having trouble with? What did your failed attempts look like? – 15ee8f99-57ff-4f92-890c-b56153 Mar 27 '15 at 18:08
  • also you should put the headers in the `` instead of the ``. That should make it easier to select as well. – DLeh Mar 27 '15 at 18:10
  • @EdPlunkett I have very poor jQuery/Javascript knowledge so i'm still learning, my attempts were beyond terrible. – Dennis Sylvian Mar 27 '15 at 18:17

1 Answers1

0

you copy just body class with jquery

 <table>

     <thead> 
    <tr>
        <th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th><th>title</th>
    </tr>
     </thead>
     <tbody class="body">
    <tr class="user">
        <td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td>
    </tr>
    <tr class="user">
        <td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td>
    </tr>
     </tbody>

Shyam Ranpara
  • 624
  • 4
  • 8