После некоторых тестов я обнаружил, что проблема заключается в исходном положении тащить. Если я начну перетаскивать индекс table2 0, все будет работать нормально.

Но если я начну перетаскивать из любой другой позиции (например, 2 ), ui.item.index() возвращает -1

Это сложная проблема, и я не могу воспроизвести ее в тестовой среде. Я оставляю часть своего кода ниже, если это поможет:
$("#table1 tbody").sortable({
connectWith: "#table2 tbody",
helper: function (e, item) {
const $helper = $("");
const $originals = item.children();
// Select the row that user is moving
table1Api.row(item).select();
const data = item.parent().children(":has(input:checked)").clone();
matchHelperSizeToOriginal(data, $originals);
// Hide siblings with checked inputs & storing the data
item.data("data", data).siblings(":has(input:checked)").hide();
return $helper.append(data);
},
start: function (e, ui) {
const data = ui.item.data("data");
ui.helper.append(data);
// Remove each dragged row
// irrelevant code here
},
stop: function (e, ui) {
// irrelevant code here
},
receive: function (e, ui) {
const nodes = ui.item.data("data");
let newIndex = ui.item.index(); // returns -1
console.log(newIndex);
},
remove: function (e, ui) {
// irrelevant code here
},
axis: "xy",
cursor: "grabbing",
});
$("#table2 tbody").sortable({
connectWith: "#table1 tbody",
items: "tr:not(:has(.dataTables_empty))",
helper: function (e, item) {
const $helper = $("");
const $originals = item.children();
// Select the row that user is moving
table2Api.row(item).select();
const data = item.parent().children(":has(input:checked)").clone();
matchHelperSizeToOriginal(data, $originals);
// Hide siblings with checked inputs & storing the data
item.data("data", data).siblings(":has(input:checked)").hide();
return $helper.append(data);
},
start: function (e, ui) {
const data = ui.item.data("data");
ui.helper.append(data);
},
stop: function (e, ui) {
ui.item.siblings(":hidden").show();
},
receive: function (e, ui) {
// irrelevant code here
},
remove: function (e, ui) {
// irrelevant code here
},
axis: "xy",
cursor: "grabbing",
});
Подробнее здесь: https://stackoverflow.com/questions/786 ... iple-items