server-side,when the pagination changes, taloses the saved selection
server-side,when the pagination changes, taloses the saved selection
Maxilboss93
Posts: 33Questions: 6Answers: 0
this is my datatable server_side:
var oTable = $tableAllievi2.DataTable({
"scrollY": "200px",
"scrollCollapse": true,
"processing": true,
"serverSide": true,
"paging": true,
"info": false,
"aLengthMenu": [
[10, 25, 50, 75, 100, 250, 500, -1],
[10, 25, 50, 75, 100, 250, 500, "All"]
],
"select": true,
"select": {
style: 'multi'
},
"pageLength": 25,
//"pagingType": "numbers",
"responsive": false,
"autoWidth": false,
"language": {
"sEmptyTable": "Nessun dato presente nella tabella",
"sInfo": "",
"sInfoEmpty": "",
"sInfoFiltered": "(filtrati da _MAX_ elementi totali)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": options,
"sLoadingRecords": "Caricamento...",
"sProcessing": "Elaborazione...",
"sSearch": "",
"sSearch[value]": "",
"searchPlaceholder":"Cerca...",
"sZeroRecords": "La ricerca non ha portato alcun risultato.",
"oPaginate": {
"sFirst": "Inizio",
"sPrevious": '<img height="35" class="arrow_sx">',
"sNext": '<img height="35" class="arrow_dx">',
"sLast": "Fine"
},
"oAria": {
"sSortAscending": ": attiva per ordinare la colonna in ordine crescente",
"sSortDescending": ": attiva per ordinare la colonna in ordine decrescente"
},
},
"ajax": {
"url": "./ajax/mediaweb/getQuizAula.php",
"data": { "listato": listato, "id_sedeClienteNeca": id_sedeClienteNeca },
"dataSrc": function (json_data) {
/*
* my code
*/
return json_data.rows;
},
},
"columns": [
{ responsivePriority: 1, "data": "__rank", className: "dt-center" },
{ responsivePriority: 1, "data": "Allievo", className: "dt-center myAnag" },
],
'stateSave': true,
'stateSaveParams': function (settings, data) {
data.selected = this.api().rows({ selected: true })[0];
},
'stateLoadParams': function (settings, data) {
savedSelected = data.selected;
},
'initComplete': function(settings) {
if (savedSelected != undefined) {
this.api().rows(savedSelected).select();
var riga = this.api().rows(savedSelected).select();
this.api().state.save();
getSelectedScrollY(riga);
} else {
this.api().rows(0).select();
}
},
"stateDuration": 60 * 30
});
oTable.on('select deselect', function (e, dt, type, indexes) {
oTable.state.save();
var count = oTable.rows({ selected: true }).count();
$(".allievi_selezionati").text(count);
});
'''
When i select many rows and after try to click on paginate_button, rows loses the selection and my data.selected become [].
How do i save the state of the table even on page change so that when i go back to the previous page it is still selected?
This discussion has been closed.
Answers
Closing as a duplicate of your other thread.
Allan