Skip to content

Commit

Permalink
Modyfind the addition of rows so that no row is added more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kitanov authored and Ivan Kitanov committed Jun 5, 2024
1 parent 9905c3e commit 54219f2
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion samples/grids/tree-grid/row-drag-base/wwwroot/GridRowDragBase.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
function addRowAndChildren(row, newData) {
if (newData.includes(row)) {
return;
}
else if (newData.length > 0 && row.Employees) {
for (let i = row.Employees.length; i >= 0; i--) {
if (newData.includes(row.Employees[i])) {
let index = newData.findIndex(element => element.ID === row.Employees[i].ID);
if (index > -1) {
newData.splice(index, 1);
}
}
}
}

for (let record of newData) {
if (record.Employees && record.Employees.includes(row)) {
return;
}
}

newData.push(row);
}
function OnRowDragEndHandler(evt) {
const ghostElement = evt.detail.dragDirective.ghostElement;
const dragElementPos = ghostElement.getBoundingClientRect();
const gridPosition = treeGrid2.getBoundingClientRect();
const withinXBounds = dragElementPos.x >= gridPosition.x && dragElementPos.x <= gridPosition.x + gridPosition.width;
const withinYBounds = dragElementPos.y >= gridPosition.y && dragElementPos.y <= gridPosition.y + gridPosition.height;
if (withinXBounds && withinYBounds) {
treeGrid2.addRow(evt.detail.dragData.data);
const newData = [...treeGrid2.data];
const draggedRowData = evt.detail.dragData.data;
addRowAndChildren(draggedRowData, newData);
treeGrid2.data = newData;
}
}

Expand Down

0 comments on commit 54219f2

Please sign in to comment.