Magesh Kumaar
Magesh Kumaar

Reputation: 1467

Datatables - Get column data based on another column data

I have table in this format

c1    c2     c3      c4

1   True    row1   row1c4
2   True    row2   row2c4
3   False   row3   row3c4
4   False   row4   row4c4

I use this to filter out the col 4 data alone

var table = $('#statustable').DataTable();
var emaillist =
            table
                .columns('c4:name')
                .data()
                .eq( 0 )      // Reduce the 2D array into a 1D array of data
                .unique()     // Reduce to unique values
                .sort()       // Sort data alphabetically               
                .join( ',' );

Now I need to filter out the column c4 based on c2 when c2 is true?

Can someone guide me?

Upvotes: 0

Views: 2218

Answers (1)

annoyingmouse
annoyingmouse

Reputation: 5699

Without access to a JSFiddle I've created this:

var table = $('#example').DataTable();
emailList = [];
table.rows().eq(0).each(function(index){
    var row = table.row(index);
    var data = row.data();
    (data[1] === "True" && emailList.indexOf(data[3]) === -1) && emailList.push(data[3]);
    return data[3];
});
console.log(emailList.join());

Working here. Hope that helps.

Upvotes: 1

Related Questions