CessK
Datatables like data entry with LiveView
Hello Everyone,
I have a question about table like data entry. And to make it as smooth as possible for the end user to add, edit and remove rows.
In previous projects i have done i have used Jquery data tables with a C# backed.
This worked very well. However i am unable to find something similar.
I have googled around and the best i could find was a 2 year old library:
I think Live View is the way to go here to implement something similar.
The use case for this would be something like a Purchase Order.
I have the main Purchase Order information and a table for the items. I would like to be able to add, update or remove items from this table.
And then able to submit a form to the _live.ex to save them as 1 object.
If there is something like this I would love to hear it as google has failed me on this.
Thanks for any information in advance!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First 7 of 7 Posts
mmmrrr
Hey @CessK!
I’m still a little confused as to what you want to achieve: do you simply have a “form” that contains a table with item information that can be updated? Then I think this should be trivial in LiveView.
Exzeitable is, as far as I understand it, for another usecase though: you have a long list of stuff you want the user to filter, sort and search. For this exzeitable looks fantastic. It doesn’t seem to be intended for editing data.
So in the end: the implementation depends on your exact set of requirements. You could also simply use the mentioned jquery library and implement the process without LiveView if you wanted to, but again: it depends.
Could you give us a little more details of what exactly you want to achieve? Then it would be simpler to formulate specific advice.
As an aside: In Elixir it often doesn’t matter that libraries seem to be “abandoned” since they are simply done. Additionally, in this particular case, the last commit is from two days ago
CessK
Hello @mmmrrr
After some trail and error i came to the following but i feel like the multiple form way is a bit weird.
Currently i am doing for general master data. like units or sizes.
then i handle all the events for a given “row” as follows
This worked but i feel like I am doing things wrong.
In the future i will have a structure as follows:
I would like to have a table to handle the items on my page to be done in a table like format:
I hope that clarifies what i am trying to do. I was hoping to do something similar to what i achieved with my master data page on a purchase order page.
mmmrrr
Understood! So your datastructure has the order information embedded as an array, so you’ll only have one changeset and the information is ephemeral and shouldn’t be persisted, correct?
In that case, I would probably use a single form around the table, so that I can still use the error tracking provided by the Ecto/LiveView integration. Then it comes down to something like this: How to use a list of items (array) with LiveView form
But in principle your implementation would also work
CessK
How would that work for table and in my example a list of change sets on a table?
That part is not very clear to me yet and the key point that I am missing.
mmmrrr
I’ll try to throw together a demo later today, if no one beats me to it
The key point is: you would only have one changeset. Your schema would contain an embedded schema which can also be used for validation.
The other option would be to persist every entry of the table to the database in which case every row would be a form (something like the edit form popover that gets generated when using the
phx.gen.livetool, just inside of the table listing). But this is not what you want to achieve, if I’m understanding it correctly.mmmrrr
So I just bootstrapped a new project called Example and generated a new resource:
mix phx.gen.live Billing Order orders title:string positions:array:mapbased on the assumption, that you want an embedded list of positions inside of your data schema.Next you need to adjust the data model. This should always be your guiding principle: Model first!
Then you’ll need to adjust the generated form component (of course this doesn’t have to be in a modal, I simply kept it that way for ease of implementation:
I hope this helps you to grok the connection between schema, changeset and form a little better.
CessK
@mmmrrr Ahh yes now i understand how it all fits together
I see now how you used field set to do the same thing i did with multiple forms.
This will help me out greatly. Thank you for the time to write this out.