I've made a drag and droppable table for sorting products.
My table looks like this:
<table class="table table-sortable" id="mytab">
<tbody>
[{foreach from=$mylist item=listitem}]
[{assign var="_cnt1" value=$_cnt1+1}]
<tr draggable="true" id="test_variant.[{$_cnt1}]">
<td class="idcount">[{$_cnt1}]</td>
<td class="[{$listclass}]">Productname</td>
<input id="sortcount[{$_cnt1}]" class="sortcount" type="hidden" value="[{$_cnt1}]"/>
</tr>
[{/foreach}]
</tbody>
</table>
My jQuery looks like this:
$(function() {
$('.table-sortable tbody').sortable({
handle: 'span'
});
$('.table-sortable tbody').sortable().bind('sortupdate', function(e, ui) {
function updateTable(){
var table = document.getElementById("mytab");
for (var i = 0, row; row = table.rows[i]; i++) {
$( row ).attr("id","test_variant."+i);
$( row ).find(".idcount").text(i);
$( row ).find(".sortcount").val(i+10);
}
}
setTimeout(updateTable, 100);
});
});
The problem is, after I drag and drop my items the dom or something doesn't exist anymore.
Like my system won't save the dragged and dropped entries (But the others which are updated but not dragged).
And what leads me here because I don't understand it is when i dragged an item and try to access it like this
document.getElementById("sortcount1").value = "200";
it just says
Uncaught TypeError: Cannot set property 'value' of null like it's not existing
I've no problem accessing the other items.
When I open the dom with clicking on elements in chrome devtools, then back to console and try it again its working again like it needs to initialize or something.
Hope someone can give me a hint.
Thank you!