The below mentioned logic you can use after checking your item is present in the table or not.
checking of item- you can do via jquery ajax call.
Logic is explained in the below URL.They are adding when add button is clicked.In your case it will be when the condition satisfies after a db call.
[
^]
Do let me know in case any queries or if you think we can modify the solution.