Hi!
I have a ListView and a Pagination control which I am populating with a limit/offset query, 20 items per page. I'm creating a "checklist" type page for myself (A list of movies, checkbox for if I've seen them or not, green/red background, etc.). It all works wonderfully, but I can't really figure out how to persist the checkbox changes back to the database.
I have managed to do so on the actual checkbox.change action (call the SQL query directly then), but that isn't the best UX, so I'd like to be able to somehow store the changes made with a primary key and the new value, then call a bulk update.
I was able to get this far:
update seen set seen = data_table.seen
from
(select unnest({{listView1.rowKeys}}::integer[]) as id_movie,
unnest({{ checkbox1.value }}::boolean[]) as seen) as data_table
where seen.id_movie = data_table.id_movie;
However, what fails there is that the "checkbox1.value" does not give me the array of all values of all checkboxes within the ListView. If I could just get that array, then I believe the postgres unnest function will just solve this for me.
The other way I tried was to figure out some way of pushing the <id_movie,seen> tuple into a set or array every time I click on the checkbox, and then use those arrays in the unnest function, but I couldn't figure out how to use an array in LocalStorage.
I also thought, maybe I could update the actual dataset returned from the query and use that in the unnest function, but didn't make any headway there.
What would be the smartest way forward here? Ideally the user browses through pages of checkboxes, click, click, click, and then hits save when she's done and all the updates get pushed down. If it's easier, it's fine to push the entire dataset down, even the unchanged stuff.