Вы сказали:
После добавления Загрузить еще появились дубли записей Где ошибка ?
<tr class="odd"><td>Входящий ответ, <a class="823nxdgfasi" href="https://control.mail.com/crm/?order=674" target="_blank">32682</a>
Барашкова Анна Александровна
Детали сделки </td><td><span class="badge bg-info">В работе</span></td><td class="sorting_1">2025-10-13 14:04:48</td><td><button type="button" class="btn totiid btn-outline-success" data-bs-toggle="modal" data-bs-target="#exampleModalScrollable1" data-totiid="2900" data-stkp="all">Принято</button></td></tr>
<tr class="even"><td>Входящий ответ, <a class="823nxdgfasi" href="https://control.mail.com/crm/?order=674" target="_blank">32682</a>
Барашкова Анна Александровна
Детали сделки </td><td><span class="badge bg-info">В работе</span></td><td class="sorting_1">2025-10-13 14:04:48</td><td><button type="button" class="btn totiid btn-outline-success" data-bs-toggle="modal" data-bs-target="#exampleModalScrollable1" data-totiid="2900" data-stkp="all">Принято</button></td></tr>
if(!empty($_POST) && isset($_POST['notifs'])){
$TBdate = date('Y-m-d');
$startDate = $TBdate;
$endDate = $TBdate;
// Handle date range filtering
if (isset($_GET['start']) && validateDate($_GET['start'])) {
$startDate = $_GET['start'];
}
if (isset($_GET['end']) && validateDate($_GET['end'])) {
$endDate = $_GET['end'];
} elseif (isset($_GET['end']) && $_GET['end'] == '') {
$endDate = $TBdate;
}
if(isset($_GET['start']) || isset($_GET['end']))
$dateTableSQL = " AND DATE(nti.notifies_create) BETWEEN '$startDate' AND '$endDate'";
else
$dateTableSQL = '';//" AND nti.notifies_create BETWEEN datetime('now', '-9999 days') AND datetime('now', 'localtime')"; //-6 //-9999 //ограничить загрузку по дням ДЛЯ АВТОМАТИЧЕСКОЙ ЗАГРУЗКИ !!!!!
$stkp_n='all';//$_POST['stkp'] передать
$limit = isset($_POST['limit']) ? intval($_POST['limit']) : 25;
$offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0;
$stkp = "SELECT nti.id as id, nti.text_notifies, nti.notifies_create, nti.status_notify, nti.text_notifies, nta.id as notify_accu_id, nta.date_closed, nta.looked_ok, nta.notifies_id
FROM notifies nti
LEFT JOIN notifies_account nta ON nti.id = nta.notifies_id
WHERE nta.account_id='{$_SESSION['id']}' $dateTableSQL ORDER BY nti.notifies_create DESC LIMIT $limit OFFSET $offset ";
$Result = $SQLite3->query("$stkp");
//$notifies_now = ResultSet($Result);
$data = [];
while ($row = $Result->fetchArray(SQLITE3_ASSOC)) {
$data[] = [
'subject' => $row['text_notifies'].' '.$STATUS_NOTIFY[$row['status_notify']][0],
'email' => ($row['looked_ok'] == 0) ? '<span class="badge bg-info">В работе</span>' : '<span class="badge bg-secondary">Прочитано</span>',
'date_create' => $row['notifies_create'],
//'status' => '', // Если нужно
/*'action' => ($row['looked_ok'] == 0)
? '<button type="button" class="btn btn-outline-success totiid" data-bs-toggle="modal" data-bs-target="#exampleModalScrollable1" data-totiid="'.$row['id'].'" data-stkp="'.$stkp_n.'">принято</button>'
: ''*/ //!!! возвратить статус включенным !!!!
'action' => '<button type="button" class="btn totiid '
. ($row['looked_ok'] == 0 ? 'btn-outline-success' : 'btn-outline-warning')
. '" data-bs-toggle="modal" data-bs-target="#exampleModalScrollable1"
data-totiid="'.$row['id'].'"
data-stkp="'.$stkp_n.'">'
. ($row['looked_ok'] == 0 ? 'Принято' : 'Рабочая')
. '</button>'
];
}
$hasMore = count($data) === $limit;
echo json_encode([
'data' => $data,
'hasMore' => $hasMore
]);
exit;
}
const savedLength = localStorage.getItem("table1_length") || 10;
let offset = 0;
const limit = parseInt(savedLength);//50;
let loading = false;
let allLoaded = false;
let lastID = parseInt($('#lastIDtd').val()) || 0;
let table;
$(document).ready(function(){
$("form").submit(function(e){
e.preventDefault();
console.log(e);
console.log(e + ' form');
});
table = $('#table1').DataTable({//var table
'responsive': true,
//"paging" : false,
//"searching" : false,
//"ordering" : true,
scrollCollapse: true,
"pageLength": savedLength,
scrollY: '880px',
"order": [[2,'desc']],
//"columnDefs": [{"type":"date","targets"}],
//"columnDefs" : [{"targets":3, "type":"date-eu"}],
"columnDefs": [ {"targets": 3, "searchable": false, "orderable": false, "visible": true} ],
//"bInfo": true,
processing: true,
"language": {"url": "/ru/datatable/Russian.json" }, // "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Russian.json"}
// ajax: '?page=dev-test&action=list_orgs',
ajax: {
method: 'POST',//type: 'POST',
//url: '?page=dev-test&action=list_orgs',
url: window.location.href,
// contentType: 'application/json',
// dataType: 'json',
data: function(d) {
/*return $.extend({}, d, {
//group: currentGroup
deal: currentGroup
});*/
d.notifs = true;//action
d.limit = limit;
d.offset = 0;
d.start = getUrlParameter('start') || '';
d.end = getUrlParameter('end') || '';
d.stkp = getUrlParameter('stkp') || 'all';
//d.applications = {"data" : ["box","www"]};
},
success: function(data){
offset = limit;
},
error: function (e) {
console.log("There was an error with your request...");
console.log("error: " + JSON.stringify(e));
},
dataSrc: 'data'
},
columns: [
{data:'subject'},
{data:'email'},
{data:'date_create'},
//{data:'status'},
{data:'action'}
]
});
function getUrlParameter(name) {
var params = new URLSearchParams(window.location.search);
return params.get(name);
}
function loadMoreData() {
if (loading || allLoaded) return;
loading = true;
//table1.processing(true);
$('#table1_processing').show();
$('#loadMoreBtn').prop('disabled', true).text('Загрузка...');
$.ajax({
url: window.location.href,//'ajax/inbox_data.php',
method: 'POST',
dataType: 'json',
data: {
notifs: true,
limit: limit,
offset: offset,
start: getUrlParameter('start') || '',
end: getUrlParameter('end') || '',
stkp: getUrlParameter('stkp') || 'all'
},
success: function(response) {
if (response.data.length > 0) {
//const table = $('#table1').DataTable();
table.rows.add(response.data).draw(false);
offset += limit;
} else {
allLoaded = true;
}
loading = false;
if (!response.hasMore || response.data.length < limit) {
$('#loadMoreBtn').hide();
} else {
$('#loadMoreBtn').prop('disabled', false).text('Загрузить ещё');
}
// после загрузки — прокрутка к таблице
/*const table1_wrapper = document.querySelector('#table1_wrapper');
if (table1_wrapper) {
table1_wrapper.scrollIntoView({ behavior: 'smooth', block: 'start' });
}*/
const scrollBody = document.querySelector('.dataTables_scrollBody');
if (scrollBody) {
scrollBody.scrollTo({ top: 0, behavior: 'smooth' });
}
//$('#table1_processing').hide();
},
error: function() {
alert("Ошибка при загрузке данных");
$('#table1_processing').hide();
},
complete: function() {
loading = false;
$('#table1_processing').hide();
}
});
}
// Первая загрузка
//loadMoreData();
// Кнопка загрузки
$('#loadMoreBtn').on('click', function () {
loadMoreData();
});
setTimeout(() => {
$('#table1_wrapper .dataTables_scrollBody').on('scroll', function() {
let scrollBody = $(this);
if (scrollBody.scrollTop() + scrollBody.innerHeight() >= scrollBody[0].scrollHeight - 50) {
// Почти внизу — загружаем ещё
loadMoreData();
}
});
}, 1000); // можно обернуть в setTimeout или поставить после инициализации
// Прокрутка при переключении страницы
$('#table1').on('page.dt', function () {
const table1_wrapper = document.querySelector('#table1_wrapper');
if (table1_wrapper) {
table1_wrapper.scrollIntoView({ top: 0, behavior: 'smooth' });
}
const scrollBody = document.querySelector('.dataTables_scrollBody');
if (scrollBody) {
scrollBody.scrollTo({ top: 0, behavior: 'smooth' });
}
});