I have a datatable with some checkboxes and when a button is clicked I want those checked rows to run through a separate query that returns a JSON with rows that will replace the rows in the current table. Using the 1.10+ api how can I redraw the contents of the table with the new ajax request?
Currently this is my code for the button:
$('#compareRowButton').on('click', function() {
var cells = dTable.cells( ).nodes();
var post_ids = [];
$.each(cells, function(i, e){ // iterate each row
var checkbox = $(e).find('input.compareCheck'); // find the checkbox
if(checkbox.is(':checked')) { // if this checkbox is checked
var post_id = checkbox.attr('value'); // get the value
post_ids.push(post_id); // push it inside the container
}
});
if (post_ids.length > 0) {
//dTable REINIT
dTable.clear().draw();
//end
}
});
which clears the rows of the table but I need to then repopulate the table with the new query while sending the post data (the values of the checkboxes in the checked rows)
I'm thinking something along the lines of this where the dTable.clear() function currently is (but have not attempted this):
$.ajax({
type : 'post',
url : 'query/compare_baddebt.php',
data: {post_id: post_ids},
dataType: "json",
success : function(r)
{
dTable.clear();
dTable.rows().add(r);
dTable.draw();
$('#compareRowButton').hide();
$('#returnToResultsButton').show();
}
Can any datatables users let me know if this code will theoretically correctly populate my table with the new set of rows?
I am mostly asking this question because the datatables site is littered with legacy api functions and I have no idea where to differentiate from <1.10 and 1.10 api calls as that site is an utter mess.
Aucun commentaire:
Enregistrer un commentaire