How do I add rows to a local table?

I'm not sure the best way to do this. I'm working on a Claim Creation App with a header section as well as a detail section. I'd like for the detail section to function kind of like a local table prior to the user posting the entire claim. So the user would be able to add rows to the detail and make changes to the fields in it. Then, after they click a button to post the entire claim would it add the header row and the detail row/s to the table in Snowflake.

I understand how to add to and update the tables in Snowflake. I'm just not sure how to handle this sort of temporary state/local table and the addition of rows to it. Any suggestions??

Hey BROMETHIUS! This should be possible using a table with event handlers, a temporary state variable, and some javascript. A temporary state variable would enable you to store and edit your frontend data. It would also allow you to set an initial value. This would enable you to predefine the structure of your data and therefore set the columns in your table, even without any data.

You would just need to set up some logic in JS queries with event handlers on your table to trigger them. These JS queries could use state.setValue or state.setIn to manage the data stored in your temporary state variable.

One thing to note is that temporary state variables are reset when the page is refreshed.

If you need a slightly more permanent storage solution then you could use localStorage as an alternative.

I hope this helps!

Hi Everett, sorry. I'm still trying to figure this out. So I have a table that is based on a temporary state table. I also have a query that will create a new row on this table using setValue.

The problem is that when it adds a row, all the rows that were edited revert back to what shows in the temporary state table. As such I've been trying to use setIn to store the edited values in the table to the temporary state before creating the new row.

I've been trying to use all sorts of variations of this to save all rows and columns from the table back to the temporary state.

Temp_State_Detail.setIn([i], {"Category": [], "Charge Description": ["Charge Description"], Line: [], Qty: [], "Unit Price": ["Unit Price"]})

Any thoughts on what I'm doing wrong?

Hey BROMETHIOUS, I can't see how your data is structured but I was able to set this up if my temp state data is structured as an array of objects. Here is what my setup looks like

Since table1.changeSet preserves the index of the row in the table where the edits were made, I looped over the keys of changeSet to get those indexes to key into the correct indexes in the state variable. I used the objects from recordUpdates to replace each entire row object with the updated row object in the temp state variable.

And it seemed to work. I hope this helps! :blush:

Hi @BROMETHIOUS, Could you share what the data stored in your Temporary State variable looks like? How you use setIn to set data in the temp state depends on the structure of your data.

It sounds like you're trying to save the edits shown on the table to the temporary state variable. Is that right? If so, then you would need to reference the table1.changeSet and/or table1.recordUpdates properties instead of the property.