Populating select element from database table
Populating select element from database table
I need to populate a select element from another (unrelated) table. This other table is just a list of valid entries for the select field. I think that I need to return an array that contains the entries that should populate the options of the field in the Editor. It seems that a function could return that array. However, I don't have a sense of how to get the contents of this other, unrelated table in the context of an Editor for the table I'm working on.
Consider that I have a 'category' field in Table A. I also have a Category table that contains the list of valid entries for the 'category' field of Table A. In the Editor for Table A, I need to offer a select element containing the contents of the 'category' table.
I can easily do this outside of DataTables/Editor, but I need to do it within the Editor.
This question has an accepted answers - jump to answer
Answers
Assuming you are using the PHP or .NET libraries for Editor, you can do this with the
Options
class.Allan
Allan,
I think I understand how to handle the category instance (I only need the category name to go into the category field in the tickets table, which is not fully shown):
What I'm not understanding is how to use this idea with a separate table that is not related to/joined to the original table.
Thanks,
Tom
Allan,
OK. I see that it just works! I had thought I would need some way to call something that would return the category array as json and then populate the array with that. It seems that Editor is able to figure that out on its own, without the need of a join. That's wonderful, and I'm sorry I didn't expect that from the beginning so as not to bother you.
I really like the DataTables/Editor software, and the more I do, the more I like it, even if I have to ask too many questions.
Thanks,
Tom
Great to hear you've got it working. Delighted to hear that you are enjoying using it!
Allan
If I may add a question about the Render () method in C# .net / Options:
https://editor.datatables.net/docs/1.7.0/net/html/548cc5ab-9cc6-c58d-28da-acfd0789669b.htm
I'm wondering how the Render function is to use. Could you give me a hint, Allan?
Best,
Markus
Hi Markus,
With a lambda function:
Documentation is available here.
Allan