3

Hi i want to add the row selection check box in data table, also need to add the check box against every row. So that it will select the row individually.

Thanks.

vels4j
  • 11,208
  • 5
  • 38
  • 63
Hemant
  • 47
  • 1
  • 9
  • no clue about your working env, what kind of language, framework? – vels4j Dec 08 '16 at 05:37
  • I am working in php framework, and i have added the datatable to show the result from databade. – Hemant Dec 08 '16 at 05:39
  • Check this links http://stackoverflow.com/questions/17671815/how-can-i-add-a-check-box-to-a-data-table-to-be-used-to-delete-the-selected-row http://stackoverflow.com/questions/10794430/update-database-table-with-checkboxes-php-mysql – vels4j Dec 08 '16 at 05:41
  • Thanks, will check it. – Hemant Dec 08 '16 at 05:48

1 Answers1

3

You can use following code JS:

$(document).ready(function() {
    $('#example').DataTable( {
        columnDefs: [ {
            orderable: false,
            className: 'select-checkbox',
            targets:   0
        } ],
        select: {
            style:    'os',
            selector: 'td:first-child'
        },
        order: [[ 1, 'asc' ]]
    } );
} );

HTML

    <table id="example" class="display" cellspacing="0" width="100%">
              <thead>
                <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tr>
                <td></td>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>$320,800</td>
            </tr>
</table>
Nitin Pawar
  • 263
  • 4
  • 12