У меня есть таблица, созданная с помощью Thymeleaf
с установленным свойством class & th:onclick
.
Я выполняю перезагрузку данных таблицы после добавления новой записи в базу данных. Перезагрузка выполняется через Ajax, считывающим файл json и применяющим изменения через table.ajax.reload
.
После перезагрузки мне кажется, что я теряю все свойства styling и onclick, поскольку они просто не срабатывают.
Моя HTML-таблица:
<table class="table table-hover" id="main-table">
<thead class="thead-inverse">
<tr>
<th class="col-md-2 text-center">Network Id</th>
<th class="col-md-2 text-center">Rep date</th>
<th class="col-md-2 text-center">Hashrate [KH/s]</th>
</tr>
</thead>
<tbody>
<tr style="cursor: pointer;" th:each="networkHashrate : ${networkHashrates}" th:onclick="'javascript:openPoolModal(\''+ ${networkHashrate.id} + '\');'">
<td class="text-center" id="hashrateId" th:text="${networkHashrate.id}"> Sample id</td>
<td class="text-center" id="repDate" th:text="${@findAndDisplayDataService.formatDate(networkHashrate.repDate)}">Sample rep-date</td>
<td class="text-center" id="hashrate" th:text="${@findAndDisplayDataService.formatHashrate(networkHashrate.hashrate)}">Sample hashrate</td>
</tr>
</tbody>
</table>
Функция, которая выполняет перезагрузку:
var table;
$(document).ready(function() {
table = $('#main-table').DataTable({
ajax: {
url: '/refresh',
//type: 'json',
dataSrc:''
},
paging: true,
lengthChange: false,
pageLength: 20,
stateSave: true,
info: true,
searching: false,
"columnDefs": [
{
"className": "text-center",
"targets": 0,
"data": "id",
},
{
"className": "text-center",
"targets": 1,
"data": "repDate.year",
},
{
"className": "text-center",
"targets": 2,
"data": "hashrate",
}
],
"aoColumns": [
{ "orderSequence": [ "asc", "desc" ] },
{ "orderSequence": [ "asc", "desc" ] },
{ "orderSequence": [ "desc", "asc" ] }
],
"order": [[ 0, "asc" ]]
});
});
setInterval(function(){
table.ajax.reload(null, false);
}, 8000);