Loading row specific data into nested editor, is it possible?
Loading row specific data into nested editor, is it possible?
I have a datatable which contains a list of products from a table called 'productMain' in my database, I intend on allowing the user to edit details of each product by using the editor modal after selecting a product.
I have a separate table in the database called 'sellingPrices' which contains a series of 'from' and 'to' dates along with a 'price' that is valid between those dates for a 'productID'.
I want to use the new nested editor feature to allow the user to see a list of upcoming prices that are relevant for that product and then create, edit or delete as appropriate.
I have used the Nested Editing example ( https://editor.datatables.net/examples/datatables/nested.html ) to get so far but that only allows me to load the data for the nested editing once as the page loads. I need to load this data each time a user edits a row while passing in a 'productID' so that I get all the relevant prices for the selected product.
Is this something editor is capable of or should I be doing this another way?
Thanks
Stephen
This question has an accepted answers - jump to answer
Answers
Hi Stephen,
Great question - yes it is possible, but it requires a little bit of extra coding to load in the options that are specific to each row as it is edited.
What you need to do is use
dependent()
to make a call to the server to get the list of options for the row being edited - the JSON return from the server can containoptions
for the fields, including the DataTable target.I can see others being interested in this as well - we'll write up a blog post about how to do it.
Regards,
Allan
Hi Allan,
Thank you very much for the advice. I must admit, I'm finding it hard to get my head around how I can use that in my scenario so a blog post about it sounds very helpful. In the meantime, I'll have a play about and see if things get a bit clearer.
Thanks
Stephen
Hi Stephen,
Just been discussing how to do an example of this with my colleague Sandy and we remembered that we have this blog post which shows how
dependent()
can be used to update options based on another value in the row.Are you basically looking for that, but with the "Country" field (the one with the dynamic options) to be a
datatable
? If so, follow along with that blog post and addtype: 'datatable'
to the country field rather thantype: 'select'
. Otherwise it is just the same.Thanks,
Allan
Hi Allan,
Thank you very much for taking the time to look into this further.
I have looked at the example from that previous blog post and managed to implement it into my solution.
I am using a 'productID' field as the dependant to perform a lookup on that products upcoming selling prices. So far as it getting the initial set of data that I need loaded; it's working well. I have noticed that when I close the editor modal and then choose another product the datatable that the dependant data is loading into isn’t clearing down so I end up with the previous products selling prices as well as the new ones.
Once I have that working the next stage is to allow users to create a new selling price for that product, so I'll need to make sure when creating a new row in the nested table it’s using the 'productID' from the main form.
I am going to purchase one of your support packages next week as I feel this is getting into the realms of being specific to my use case and I want to make sure that where possible I'm using datatables and editor to their full extent.
Thanks,
Stephen
Hi Stephen,
Are you able to give me a link to your page so I can debug the issue please? You can drop it to me in a PM if you don't want to make it public (click my forum user name above and then the "Send message" button).
Thanks,
Allan