I have a ListView with Input Fields. I am able to dynamically add input rows. (e.g Dynamically appending form Fields)
How can I use the data from the ListView to perform a Bulk Insert into MySQL database?
Can I do this directly by creating a SQL write query with Bulk Insert, using the Listview as the Array?
It really depends on the fields in your database and the names of the components in the listview.
If your fields have the same naming as the columns in the DB, you should be able to directly use the listview.data property like so:
If they do not match though, you will probably need to either use a transformer, or map the data inline in your query.
If you are able to share what you have so far, I am happy to take a look and give more specific feedback!
Thank you Mark! Naming the fields to match the DB columns makes things a lot easier. It works!
In a nut shell, I have a form with 2 fields:
Invoice_ID and Lease_ID(Invoice_ID is pre-populated by a database sequence).
Inside the form, I have a listview with the details.
TRANSACTION_TYPE, AMOUNT, DESCRIPTION
I have Add Row and Delete Row buttons to increase/decrease the number of rows in the ListView (for the number of charges for each invoice).
Each row in the database will essentially be:
INVOICE_ID, LEASE_ID, TRANSACTION_TYPE, AMOUNT, DESCRIPTION. (There are other fields but they will be auto-populated at the database level).
To use the INVOICE_ID and LEASE_ID fields without any transformer or JS mapping, I simply created 2 "non-visible" fields in the ListView and pre-populate them by copying over the values from the form.
I think this simplifies everything and seems to work!
Hi Mark - one question.
Given the screenshot example you've provided, what if I wanted to manipulate data before insert? For example, the ID values (123, 4423, 234) - if I wanted to multiply them by 10 before inserting them, is there a way to do this in one step here?
You could use
Object.assign() do something like this: