Однако он не срабатывает на третьей и остальных страницах, ошибок console.log нет.
Очевидно, проблема связана с реконструкцией DOM через DataTable. Параметры initComplete, которые, как я полагаю, применяются только для первой таблицы данных результатов, поэтому он вызывает мою функцию status_icons() только на второй странице результатов, а не на остальных.
Моя глобальная функция, которая запускает разбиение на страницы DataTable при событии клика
Код: Выделить всё
function status_icons() {
$('table tr').each(function() {
if ($(this).find('td').eq(0).text() == '1') {
$(this).find('td').eq(0).replaceWith('[i][/i]');
$(this).find('.btn-success').eq(0).prop("disabled", true);
$(this).find('.btn-success').eq(0).text('Paid');
} else {
$(this).find('td').eq(0).replaceWith('[i][/i]');
}
});
}
Код: Выделить всё
setTimeout(function() {
$('#invoices-table').DataTable({
responsive: true,
columnDefs: [{ orderable: false, targets: [-1, -2, -3] }],
"lengthMenu": [
[100, 5, 25, 50, -1],
[100, 5, 25, 50, "All"]
],
dom: 'Bfrtip',
initComplete: function() {
status_icons() // it executes my function for the first page of results
var api = this.api();
// some irrelevant code that uses api and does not cause my issue
// ...
$('.paginate_button').on('click', function() {
status_icons(); // it executes for the second page but not for the rest
});
}
});
}, 3000);
https://cdn .datatables.net/1.10.10/js/jquery.dataTables.js
Подробнее здесь: https://stackoverflow.com/questions/442 ... ot-on-rest
Мобильная версия