beforeRemoveRow, I need send the data to server and wait the response

Tags: #<Tag:0x00007f0b02b72208>

Hi, I am not sure how to achieve this function.

Before remove a row,

I need send request to server to query some data and until I get the response, I would decide if I should remove the row.

I am trying to use the beforeRemoveRow hook and afterRemoveRow hook.

If you have any idea or demo code, please share it with me.

Thank you.

Hi @springyulei

the beforeRemoveRow is exactly what you need. Can you share the rest of the code? I do not know why it does not work for your example. You just need to know that when the call is sent the row is deleted so I recommend adding a condition true/false for the deletion to happen when you get an answer from the server.

Hi @aleksandra_budnik

Thank you for your quick reply.

It works fine usually.
I should say How to use Promise inside of the beforeRemoveRow Callback function.

As I need a Promise to call the server and get the data

Is there anything else I can do for you @springyulei
Unfortunately we do not have any examples on how to connect Handsontable to a database

If I understand correctly, I would suggest that the function attached to beforeRemoveRow be async, and then you can await the server’s response and check if you will return false or not. The await will cause execution to stop until the promise is resolved, unlike promise.then() which just attaches a function and continues execution.

I have the same issue. I have an async call to the server and I’m waiting for it to send me back its response based on which I’ll decide if the row can be deleted.
I try with beforeRemoveRow to return a bool but the row gets deleted immediately, unless of course I set up the return value to false before the async.
How can I make HOT wait for my async?

Hi @artur.abato.janas

how do you trigger removing of rows? Do you use dropdownMenu/contextMenu or alter method?

1 Like

Hi Alexandra, I’m using the contextMenu as per the docs example. It’s in items object and uses property called remove_row.

You can try to overwrite this option via custom contextMenu and after the server returns his result you call the alter method to remove the rows.

1 Like

Hi Alex, thanks that’s perfect! Works like a charm! thanks for fast response!

You’re welcome. I’m happy that I could help :slight_smile: