Double DataTable

Copy rows from one to the other

by Scott Smith

HTML

<link rel="stylesheet" href="ttps://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/dataTables.jqueryui.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/scroller/1.4.2/css/scroller.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.4/css/buttons.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/dataTables.jqueryui.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/select/1.2.1/js/dataTables.select.min.js"></script>
<script src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.colVis.min.js"></script>
      <div>


            <table width="100%" class="display" id="example" cellspacing="0">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                        <th>Btn</th>
                    </tr>
                </thead>

                <tbody></tbody>
            </table>
            <br />
            <table width="100%" class="display" id="example2">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>

                    </tr>
                </thead>

                <tbody></tbody>
            </table>

        </div>

JavaScript

$(function ($) {


$("#example").one("preInit.dt", function (evtObj, settings){

    var $newbtncontainer = $("<div class='dt-buttons'></div>");
    $("#example_wrapper").prepend($newbtncontainer);
    $("a.buttons-colvis").appendTo($newbtncontainer);
});


            var tb = $("#example").DataTable({
                paging: false,
                select: "multi",
                searching: true,
                info: false,
                columnDefs: [{
                    targets: [-1],
                    render: function () {
                        return "<button type='button'>M</button>"
                    }
                }],
                data: aa,
                columns: [{
                    data: "name"
                }, {
                    data: "position"
                }, {
                    data: "salary"
                }, {
                    data: "start_date"
                }, {
                    data: "office"
                }, {
                    data: "extn"
                }, {
                    data: null
                }],
//https://cdn.datatables.net/buttons/1.2.4/js/buttons.colVis.min.js 
                dom: 'ftBip',
                buttons: [
                    {extend:'colvis', text:'ColVis'},
                    {
                    extend: "selectRows",

                    text: 'Move Selected Rows',
                    action: function (e, sourceTable, button, config) {

                        var selectedRows = sourceTable.rows(".selected");
                        var mData = selectedRows.data();
                        // I tried making a copy of the entire data object using JSON but it
                        // gave me a circular reference error so I am doing it row at a time.
                        // remove the seleted rows
                        selectedRows.remove().draw();
                        targetTable = $("#example2").DataTable();
                        $.each(mData, function (idx,...