Fix definitivo problema totali ristretti a selezione

This commit is contained in:
loviuz 2022-10-31 11:19:44 +01:00
parent 03394391bc
commit ed964e8d2a
1 changed files with 13 additions and 18 deletions

View File

@ -16,8 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
var first_load_complete = false;
function start_local_datatables() { function start_local_datatables() {
$('.datatables').each(function () { $('.datatables').each(function () {
if (!$.fn.DataTable.isDataTable($(this))) { if (!$.fn.DataTable.isDataTable($(this))) {
@ -350,25 +348,21 @@ function initComplete(settings) {
setTimeout(function () { setTimeout(function () {
$('.select-checkbox').each(function(){ $('.select-checkbox').each(function(){
if (first_load_complete) { var row = $(this).parent();
var row = $(this).parent(); var row_id = row.attr("id");
var row_id = row.attr("id");
var table_selector = $(this).closest(".dataTable"); var table_selector = $(this).closest(".dataTable");
var wrapper = getTable(table_selector); var wrapper = getTable(table_selector);
if(typeof row_id !== "undefined"){ if(typeof row_id !== "undefined"){
if (row.hasClass("selected")) { if (row.hasClass("selected")) {
//table.datatable.rows("#" + row_id).select(); wrapper.addSelectedRows(row_id);
wrapper.addSelectedRows(row_id); } else if (!row.hasClass("selected") && row.hasClass("clicked")) {
} else { wrapper.removeSelectedRows(row_id);
//table.datatable.rows("#" + row_id).deselect();
wrapper.removeSelectedRows(row_id);
}
} }
} }
}); });
}, 1000); }, 100);
} }
function drawCallback(settings) { function drawCallback(settings) {
@ -406,8 +400,6 @@ function drawCallback(settings) {
}).select(); }).select();
} }
}); });
first_load = true;
} }
function footerCallback(row, data, start, end, display) { function footerCallback(row, data, start, end, display) {
@ -497,6 +489,9 @@ function getTable(selector) {
addSelectedRows: function (row_ids) { addSelectedRows: function (row_ids) {
row_ids = Array.isArray(row_ids) ? row_ids : [row_ids]; row_ids = Array.isArray(row_ids) ? row_ids : [row_ids];
row_ids.forEach(function (item, index) { row_ids.forEach(function (item, index) {
// Aggiungo una classe per definire che questo elemento è stato cliccato ora,
// per poterlo de-cliccare correttamente
$('tr[id='+item.toString()+']').addClass('clicked');
selected.set(item.toString(), true); selected.set(item.toString(), true);
}); });