Condition to select all rows all pages

Condition to select all rows all pages

thiagoemanoelthiagoemanoel Posts: 6Questions: 1Answers: 0

Hi guys , i'm using datatables and i have created a column with a input type checkbox

<th><input type="checkbox" id="check_all"></th>

when a check this checkbox he call a function javascript .

  $(document).on('click','#check_all',function(e){

        var table2 = $('.datatable').DataTable();

        table2.rows({ search: 'applied' }).select();
    });

this select all rows based on what i have search .

inside my datatables script i have a function render that do this .

    { data: 'sync',
                        'searchable': false,
                        'orderable':false,
                        'render': function (data, type, row) {


                            if(row.sync==1){
                                return '<button value=1>Send</button>';

                            } else{
                                return '<button value=0>Waiting</button>';
                            }

                        }
                    },

its possible to select only rows that have button value 0 or for example , select rows that have text "Waiting" ?

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    You can use the rows() row-selector as a function an return only the rows you want to select. See the function example for how to do this.

    Kevin

  • thiagoemanoelthiagoemanoel Posts: 6Questions: 1Answers: 0
    edited September 2020

    hey Kth , i put this inside my check_all function

     var indexes = table2.rows().eq(0).filter(function(rowIdx){
    
                return table2.cell(rowIdx,3).data()=='0'? true : false;
            });
    
     table2.rows(indexes).nodes().to$().addClass('highlight');
    table2.rows('.highlight').select();
    

    in my column 3 i search for the value '0' if true the class 'highlight' append to him . after this , only the rows with hightlight class are selected , but this dont consider the search , so the real situation must be

    "class" and "search" ? its possible this combination ?

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    I was thinking something more like this:

    table2
        .rows( function ( idx, data, node ) {
            return data.sync === 0 ?
                true : false;
        }, { search: 'applied' } )
        .select();
    

    Kevin

This discussion has been closed.