
Hi Rajasekhar,In Lightning, we don't manually move elements around (e.g. tar.appendChild(document.getElementById(data))). Instead, we reorder the data, and the platform takes care of it for us. The design pattern you have isn't optimal, but for sake of keeping it simple, here's the modified drop function you'd use:
({
drop: function (component, event, helper) {
var data = event.dataTransfer.getData("text");
// Find the record ID by crawling up the DOM hierarchy
var tar = event.target.closest('[id]');
var contactData = component.get("v.ContactData");
var index1, index2, temp;
// Find the index of each item to move
contactData.records.forEach((v,i)=>{if(v.Id===data) index1 = i; if(v.Id===tar.id) index2 = i;});
if(index1<index2) {
// Lower index to higher index; we move the lower index first, then remove it.
contactData.records.splice(index2+1, 0, contactData.records[index1]);
contactData.records.splice(index1, 1);
} else {
// Higher index to lower index; we remove the higher index, then add it to the lower index.
temp = contactData.records.splice(index1, 1)[0];
contactData.records.splice(index2, 0, temp);
}
// Trigger aura:valueChange, component will rerender
component.set("v.ContactData", contactData);
event.preventDefault();
}
})
There's no real error checking here, so you might want to take care of situations like when a user drops on to an area that isn't covered by a DOM element that has an ID.
Hope this helps.Kindly mark this as solved if the reply was helpful.Thanks,Nagendra
1 risposta