Row Action "DEL" always deletes the last row instead of the clicked one

Hey @krsailer82 ,

I've uploaded the updated app JSON (with the new JS query) to your shared Google Drive folder. Just to share here as well, below is the JavaScript query I updated in the app:

// Step 1: Start with original table data from the variable
let mergedData = [...table_data_var.value];

// Step 2: Apply all changes from changesetArray into the merged data
table_entry_inven.changesetArray.forEach((change, index) => {
  mergedData[index] = { ...mergedData[index], ...change };
});

// Step 3: Set merged data back into the variable (table data source)
table_data_var.setValue(mergedData);
  //  Clear changesetArray by resetting the table data source
 table_entry_inven.clearChangeset();

// Step 4: Get the selected index
const selectedIndex = table_entry_inven.selectedDataIndex;

// Step 5: Validate and remove the row at the selected index
if (
  selectedIndex !== undefined &&
  selectedIndex >= 0 &&
  selectedIndex < mergedData.length
) {
  // Remove the row
  mergedData.splice(selectedIndex, 1);

  // Step 6: Update the variable again with row removed
  table_data_var.setValue(mergedData);

  table_entry_inven.setData?.(mergedData); // use only if table supports setData()

  utils.showNotification({
    title: "Deleted",
    description: `Row at index ${selectedIndex} has been removed.`,
    type: "success",
  });
} else {
  utils.showNotification({
    title: "Error",
    description: "No valid row selected to delete.",
    type: "error",
  });
}

Let me know if you run into any issues while reviewing or testing it out.

2 Likes