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.

4
  • no clue about your working env, what kind of language, framework? Commented Dec 8, 2016 at 5:37
  • I am working in php framework, and i have added the datatable to show the result from databade. Commented Dec 8, 2016 at 5:39
  • Check this links stackoverflow.com/questions/17671815/… stackoverflow.com/questions/10794430/… Commented Dec 8, 2016 at 5:41
  • Thanks, will check it. Commented Dec 8, 2016 at 5:48

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I have a feeling this wouldnt add the checkbox if you used row.add([])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.