simple case, but I can't deselect all rows

simple case, but I can't deselect all rows

m.arditom.ardito Posts: 5Questions: 4Answers: 1
edited January 2017 in Free community support

Hi, I'm a datatables newbie so forgive me if I'm making obvious mistakes:

I've read many examples on the website, then I downloaded the examples, and tried to customize a simple one ( "Row selection (multiple rows)" ).

Then I tried to add another button to deselect all rows but, after trying all sorts of API calls I keep failing... but I know I'm a newbie.

I need help... thanks for any hint.

While the is console logging: "TypeError: table.rows(...).deselect is not a function". The example "row count works"

here's the code I'm using in the "init" script:

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

    $('#example tbody').on( 'click', 'tr', function () {
        $(this).toggleClass('selected');
    } );

    $('#button').click( function () {
        alert( table.rows('.selected').data().length +' row(s) selected' );
    } );

    $('#reset').click( function () {
        
        table.rows().deselect();
    } );
    
} );

and this is how I altered the example table code

<button id="reset">Reset</button>
<button id="button">Row count</button>

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>

This question has an accepted answers - jump to answer

Answers

  • m.arditom.ardito Posts: 5Questions: 4Answers: 1
    edited January 2017 Answer ✓

    Ok, "solved"... I wasn't loading the select extension .js... otherwise it works... o:)

  • allanallan Posts: 63,696Questions: 1Answers: 10,500 Site admin

    That's for posting back. Good to hear you've got it working.

    Allan

This discussion has been closed.