
Originariamente inviata da
pippuccio76
Salve a tutti ho una datatable con paginazione automatica ( di default datatable) , alla prima colonna ho un checkbox con value = all'id del record del database , quando seleziono i singoli checkbox su pagine diverse mi riporta solamente quello della pagina visibile .
Il tutto funziona invece se seleziono tutti i valori con questa funzione :
codice:
$( "#seleziona_tutto" ).change(function() {
var checked ;
if($("#seleziona_tutto").is(':checked')){
checked = 1 ;
}else{
checked = 0 ;
}
table.column(0).nodes().to$().each(function(index) {
if (checked) {
$(this).find('.scegli_viaggi').prop('checked', 'checked');
} else {
//$(this).find('.scegli_viaggi').removeProp('checked');
$(this).find('.scegli_viaggi').prop('checked', false);
}
});
table.draw()
});
Come posso fare per i singoli record ?
Scusate in realtà la funzione che controlla tutti i checkbox di tutta la datatable è questa :
codice:
$('form').on('submit', function(e){
var $form = $(this);
// Iterate over all checkboxes in the table
table.$('input[type="checkbox"]').each(function(){
// If checkbox doesn't exist in DOM
if(!$.contains(document, this)){
// If checkbox is checked
if(this.checked){
// Create a hidden element
$form.append(
$('<input>')
.attr('type', 'hidden')
.attr('name', this.name)
.val(this.value)
);
}else{
// remove input type hidden
$("input[type='hidden']").remove();
}
}
});
});
Ma non funziona con i checkbox selezionati singolarmente ma solo con tutti