rivkamak
asked on
Jquery datatable get date from hidden rows
I am using jquery datatable, with a checkbox to select 1 for each row.
as the person clicks through the checkboxes I need to calculate how much money the items will cost based on which boxes are checked.
Right now, it's only calculating the visible rows.
Is there any API that I can use to get which checkboxes are clicked off?
if I try to use something like oTable.rows().every( ), it is displaying the text as it was when the table was written before it gets checked.
as the person clicks through the checkboxes I need to calculate how much money the items will cost based on which boxes are checked.
Right now, it's only calculating the visible rows.
Is there any API that I can use to get which checkboxes are clicked off?
if I try to use something like oTable.rows().every( ), it is displaying the text as it was when the table was written before it gets checked.
Hi, Try to add some code of references so we could understand better and you get help quickly.
ASKER
$(document).ready(function() {
oTable= $('#listcars').DataTable({
"order": [[ 6, "asc" ]],
});
//if checked this year calculate, otherwise not.
$( "input[id^='pay']" ).click(function() {
for ( var i = 19; i> 0;i-- ){
if ($( "#pay" + i ).is(":checked") ) {
console.log($(this).attr('data-cost'));
}
}
oTable.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
console.log('ind: ' + rowIdx);
var data = this.data();
console.log(data[0]);
} );
});
My id is 1 per row.The first loop only goes through the first 10 row that are currently visible. After that I get undefined.
The second loop displays each row as straight text when the page was drawn and not including any currently checked off boxes.
You need to use the event delegation on like :
$("#listcars").on("click", "input[id^='pay']", function() {
for ( var i = 19; i> 0;i-- ){
if ($( "#pay" + i ).is(":checked") ) {
console.log($(this).attr('data-cost'));
}
}
});
Hi,
When you say hidden, is this from the DOM or it have the hidden class or not available because of pagination?
Some ref
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
https://datatables.net/reference/option/rowCallback
When you say hidden, is this from the DOM or it have the hidden class or not available because of pagination?
Some ref
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
https://datatables.net/reference/option/rowCallback
ASKER
It's not available becuase of pagination.
I don't want the checkbox to be there for show.
I need to know which ones are checked , even on a part of the pagination that isn't visible right now.
I don't want the checkbox to be there for show.
I need to know which ones are checked , even on a part of the pagination that isn't visible right now.
The event delegation should work I have already tested the code and it work just fine with pagination, have you tried it ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.