Add new row, BUT if data doesn't already exist in table
Add new row, BUT if data doesn't already exist in table
I have looked at some of the examples of adding a new row. However, is there a way to add a new row if the data doesn't already exist in the table?
Example:
In my table I have:
ID Make Model Year
1 Chevy 3500 2016
2 Ford F-350 2021
78 BMW X5 2022
I have a list box that shows the makes as well and has the ID set in that list box. So, when the user clicks on a
data value in the list box and want's to add it to the table, is there a way to loop through the table and if that selected ID doesn't exist, add it to the table, if it does exist, kick back a message that { item already exists } ?
Answers
Sure - use the API. Specifically you could use
rows()
with a function selector to find out if any rows exist with the data you are matching against (then useany()
to determine if any matched).Use
row.add()
to add the new row.I'm presuming it isn't with Editor you are doing this? If it is with Editor, then I'd use a server-side validator to check if a row exists.
Allan
No, I'm not using Editor. So, once the user clicks on the item, then clicks the button to add, the button function will first.
Basically repeating what Allan suggested:
Use
rows()
with arow-selector
of a function to find matching rows. Chainany()
to see if it exists.Use jQuery ajax() to send the
ID
to the server API.Isn the
success
function userow.add()
to add the row to the table.Kevin
I'm looking at the selector now. I have the API call already built and working for another section of the app.