API filter() not working on selected rows as expected

API filter() not working on selected rows as expected

krtcomkrtcom Posts: 2Questions: 1Answers: 0

Hi, does anybody have an idea why this is working differently than I would expect (and documentation states)

http://jsfiddle.net/np6w3oz4/2/

Basically when user selects several rows I need to fiter out some of them (for example odd rows). I use filter() function which should return an API instance with no more than number of selected rows. But when I check the result in console it shows all data from a table not just filtered rows

my code:

$(document).ready(function() {
    var dt = $('#example').dataTable({
        select: {
            style:    'os',
            info:false
        },
    });
    var api = dt.api();
    
    $("button.action").on("click", function(){
        var deleteRows = api.rows({selected: true});
        
        //This is OK - shows the number of selected rows
        console.log(deleteRows.data().length);
        
        var approvedDeleteRows = deleteRows.filter(function(value, index, dt){
            var data = dt.row(value).data();
            var ID = data[0];
            return ID % 2 == 0;
        });
        //This is always 10 but it should not be more than number of selected rows
        console.log(approvedDeleteRows.data().length);
    });
    
});
This discussion has been closed.