Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82669

Understanding row-selector by column value

$
0
0

I populate a table with a JSON data like this:

{
    'id' : 1,
    'name': 'Jhon',
    'category_id': 12,
},
{
    'id' : 3,
    'name': 'Max',
    'category_id': 12,
},
{
    'id' : 4,
    'name': 'Bob',
    'category_id': 23,
}

I can select a row this way

table.row({id:3})

But I can't use this for select many rows

table.rows({category_id:12})

This return ALL rows, without filter category_id:12

I read the doc at https://datatables.net/reference/type/row-selector and this doesnt help.

I found a this comment and was a similar behavior, but I want know if this is overthinking and I'm doing something wrong.

https://datatables.net/forums/discussion/49916/how-can-i-find-row-and-column-indexes-of-certain-value-with-datatable#Comment_132243

var rowIndexes = [];
table.rows( function ( idx, data, node ) {             
     if(data.somefield === somevalue){
        rowIndexes.push(idx);                  
     }
     return false;
});

I use this.

let rowIndexes = [];
table.rows( function ( idx, data, node ) {             
     if(data.category_id === 12){
        rowIndexes.push(idx);                  
     }
     return false;
});
let myrows = table.rows(rowIndexes);

Viewing all articles
Browse latest Browse all 82669

Trending Articles