jQuery DataTables – How to add a checkbox column

Example for article at http://www.gyrocode.com/articles/jquery-datatables-how-to-add-a-checkbox-column/

HTML

<link rel="stylesheet" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css">
<script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th><input name="select_all" value="1" id="example-select-all" type="checkbox" />Hepsini Seç</th>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th><input type="checkbox" id="Checkbox1" class="chk" value="1" /></th>
            <th>1</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
        <tr>
            <th> <input type="checkbox" id="Checkbox2" class="chk" value="2" /></th>
            <th>2</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>

        <tr>
            <th> <input type="checkbox" id="Checkbox3" class="chk" value="3" /></th>
            <th>3</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
        <tr>
            <th>  <input type="checkbox" id="Checkbox4" class="chk" value="4" /></th>
            <th>4</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
        <tr>
            <th><input type="checkbox" id="Checkbox5" class="chk" value="5" /></th>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
        <tr>
 ...

JavaScript

$(document).ready(function () {
        var table = $('#example').DataTable({});

        // Handle click on "Select all" control
        $('#example-select-all').on('click', function () {
            // Check/uncheck all checkboxes in the table
            var rows = table.rows({ 'search': 'applied' }).nodes();
            $('input[type="checkbox"]', rows).prop('checked', this.checked);
        });
    });

    $("#gg").click(function () {
        $("input:checkbox[class=chk]:checked").each(function () {
            alert($(this).val());
        });
    });