diff --git a/packages/nc-gui/components/project/spreadsheet/RowsXcDataTable.vue b/packages/nc-gui/components/project/spreadsheet/RowsXcDataTable.vue
index df53bc0478..26e19fa7ea 100644
--- a/packages/nc-gui/components/project/spreadsheet/RowsXcDataTable.vue
+++ b/packages/nc-gui/components/project/spreadsheet/RowsXcDataTable.vue
@@ -1124,27 +1124,8 @@ export default {
.map(c => rowObj[c.title])
.join('___');
- if (!id) {
- return this.$toast.info("Delete not allowed for table which doesn't have primary Key").goAway(3000);
- }
-
- const res = await this.$api.dbViewRow.delete(
- 'noco',
- this.projectName,
- this.meta.id,
- this.selectedView.id,
- id
- );
-
- if (res?.message) {
- this.$toast
- .info(
- `
Unable to delete tables because of the following.
-
${res.message.join('
')}
- Clear the data first & try again
- `
- )
- .goAway(5000);
+ const successfulDeletion = await this.deleteRowById(id);
+ if (!successfulDeletion) {
return;
}
}
@@ -1157,7 +1138,6 @@ export default {
},
async deleteSelectedRows() {
let row = this.rowLength;
- // let success = 0
while (row--) {
try {
const { row: rowObj, rowMeta } = this.data[row];
@@ -1170,10 +1150,10 @@ export default {
.map(c => rowObj[c.title])
.join('___');
- if (!id) {
- return this.$toast.info("Delete not allowed for table which doesn't have primary Key").goAway(3000);
+ const successfulDeletion = await this.deleteRowById(id);
+ if (!successfulDeletion) {
+ continue;
}
- await this.$api.dbViewRow.delete('noco', this.projectName, this.meta.id, this.selectedView.id, id);
}
this.data.splice(row, 1);
} catch (e) {
@@ -1183,6 +1163,32 @@ export default {
this.syncCount();
},
+ async deleteRowById(id) {
+ try {
+ if (!id) {
+ this.$toast.info("Delete not allowed for table which doesn't have primary Key").goAway(3000);
+ return false;
+ }
+
+ const res = await this.$api.dbViewRow.delete('noco', this.projectName, this.meta.id, this.selectedView.id, id);
+
+ if (res?.message) {
+ this.$toast
+ .info(
+ `Unable to delete row with ID ${id} because of the following:
+
${res.message.join('
')}
+ Clear the data first & try again
`
+ )
+ .goAway(5000);
+ return false;
+ }
+ } catch (e) {
+ this.$toast.error(`Failed to delete row : ${e.message}`).goAway(3000);
+ return false;
+ }
+ return true;
+ },
+
async clearCellValue() {
const { col, colIndex, row, index } = this.rowContextMenu;
if (row[col.title] === null) {