1

I have a jquery datatable, and have checkboxes which set the row selected class to the rows which are selected. However when I try to get the first column data from these selected rows, it gives me objects.

I am unable to get to the problem inspire of going through a number of posts on the subjects on the data tables and stack overflow forums.

The codes are provided below.

Regards, Arjun

HTML:

<table id="mytable" class="table table-striped table-bordered" cellspacing="0" width="100%">

    <thead>
            <tr>
                <th><input type="checkbox" name= "check_all" id="check_all"/></th>
                <th>Request ID</th>
                <th>Request Date</th>
                <th>Leave Type</th>
                <th>Start Date</th>
                <th>End Date</th>
                <th>Status</th>
            </tr>
        </thead>
    </table>

Javscript

$("#check_all").click(function () {
    $(".checkBoxClass").prop('checked', $(this).prop('checked'));
});

$(".checkBoxClass").change(function(){
    if (!$(this).prop("checked")){
        $("check_all").prop("checked",false);
        $(this).closest('tr').removeClass('row_selected');
    }
        $(this).closest('tr').addClass('row_selected');
});

function sendval(){
    var apprReq = [];
    var rejReq = [];

    var otable = $('#mytable').DataTable();
    var aTrs = otable.rows();

    for ( var i=0 ; i<aTrs.length ; i++ )                                       
    {
        if ( $(aTrs[i]).hasClass('row_selected') )
        {
            apprReq.push( aTrs.rows().data[i] );
        }
            rejReq.push( aTrs[i] );
    }
    console.log(apprReq);
    console.log(rejReq);

}

2 Answers 2

2

from datables doc you can do:

var table = $('#mytable').DataTable();
var rows_selected = table.rows('.row_selected').data();
$.each(rows_selected,function(i,v){
    apprReq.push(v);
});
Sign up to request clarification or add additional context in comments.

1 Comment

the data is not a function. however it works in getting all the data
0

Getting the data without using the class 'row_selected'

https://stackoverflow.com/a/45694629/3514293

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.