Editor: Is there an API to manually access data the field type select uses?
Editor: Is there an API to manually access data the field type select uses?
avit
Posts: 5Questions: 1Answers: 0
I can see the data in the json response: draw.options, but how to access this properly.
So basically instead of using a select, I want to show a readonly value from the options, when I create a new entry.
fields: [
{
label: "MyLabel",
name: "mytable.mycolumn",
type : "select"
},
]
I tried solving it by using a def value.
fields: [
{
label: "MyLabel",
name: "mytable.name",
type: "readonly",
def: function () {
return table.data().options().myOptionTable.MyField;
}
},
]
Obviously this doesn't work.
.Field(new Field("mytable.myforeignkey")
.Options(new Options()
.Table("foreigntable")
.Value("id")
.Label("name")
)
)
I don't find any interface to properly access the options.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm afraid I'm not fully understanding what you are looking for here. Do you want the
select
field to not be enabled (i.e. have it as readonly)? If so,disable()
orfield().disable()
is the way to do that.Regards,
Allan
No, sorry I'm not a good explainer
Think of a master detail view and I want to add details to the master, e.g. I want to add ingredients to a recipe, but I want to show the recipe id and name in the ingredient editor view. I cannot use a left join, because the editor fields would be empty when I create a new entry.
So my idea was, to use the primary key of the recipe, that is allready part of my backend model and ask the options API of DataTables.Editor for the correct recipe name.
When I think about it, a right join or inner join could also work, but DataTables.Editor .Net doesn't seem support them.
Thanks
Perhaps this plug-in will be of some help? If I'm understanding what you want correctly, you want to just display some information to the end user in the form, which is something that plug-in makes possible.
Allan
Unfortunately this is not what I need, I could use it at some point when my problem is solved though
So let's go deeper here, I created a minimal example to explain the concept.
Recipe view code
Back end code
I have a recipe table that redirects to the recipe-ingredient view, as soon as someone clicks on edit recipe.
In the "Create new entry" (Picture 4.) form I want to have "Pancake" there even when I click on "Create".
What is the best way to achieve that?
I'm using NancyFX as backend, but the code should be straightforward.
Thanks for the details!
In the code above you have
def: "@Model.Id",
for the id field. Can you do something similar for the name field? Is it possible to add the name to your model, so that if theId
parameter is defined, theName
parameter would also be so?If that isn't possible then the way to solve it shown the way you have above is to put an event listener on the
recipe_ingredient.recipe
to detect a change in value for that field. When that change is detected, you could either make an Ajax call to the server to determine what the correct name is for the id, or if that information is available in a local object, look it up there.You could use either
dependent()
for that orfield().input()
and assign a custom event listener.Does that all make sense?
Thanks,
Allan
Hey allan,
thanks for staying with me
Exactly this, the data is already available as local object, in the depths of DataTables and I want know how to access them properly with DataTables.Editor
See, this is the response of my backend, generated by datatables.editor .net, the field is already there, waiting for me to be used.
Sure I could just request the data again, but I would like to avoid that.
Thanks again.
Okay - with you now!
ajax.json()
will give you the latest JSON that DataTables has got back from the server - so you could do:I think that should more or less do it.
Allan
Thank you Allan,
That does the job indeed.
Now I'm weighing my options and see what fits best.
Best regards