How would I do that?
Thank you
4 Answers, 1 is accepted
A default value can be set through model's field definition. More information on the matter can be found here and here.
Greetings,Rosen
the Telerik team
I'm afraid that you cannot change the default value declaration for given model dynamically. You should consider getting the values and assigning them before constructing the Model definition.
Regards,Rosen
the Telerik team
Rosen,
Can you provide an example on how you would do this? What do you mean specifically by "getting the values and assigning them before constructing the Model definition."
Thank you!
You should retrieve the values and then use them when constructing the Model definition. For example:
var
defaultValues = getDefaultValuesFromAService();
// returns a default values as an key value map { foo: "valueFoo", bar: "valueBar" }
var
model =
new
kendo.data.Model.define({
id:
"id"
,
fields: {
foo: {
defaultValue: defaultValues[
"foo"
]
},
bar: {
defaultValue: defaultValues[
"bar"
]
}
}
});
var
dataSource =
new
kendo.data.DataSource({
schema: {
model: model
}
//....
});
Rosen
the Telerik team
As I have already stated the default values cannot be changed dynamically.
However, you may use the Grid edit event to pre-populate the edit form:
edit:
function
(e) {
if
(e.model.isNew() && !e.model.dirty) {
e.container
.find(
"input[name=ProductName]"
) // get the input element for the field
.val(
"MyCustomValue"
) // set the value
.change(); // trigger change in order to notify the model binding
}
}
All the best,
Rosen
the Telerik team
I'm using Kendo Grid Popup to add/edit data in MVC. When I add new record the ModelID field value remain 0 only. So when I try to edit the newly added record, instead of updating existing record it adds new record again. How to set ModelID field value when adding new record?
Also, I've drop downs on popup. I'm populating dropdowns from separate controller action. Could you please let me know how to populate dropdowns from List<T> property of same view model which is used to add/edit popup.
Regards,
Dilip
As you may know the value of the id field determines if the record is new (when the value is set to the default) or it is already existing (if id value is different than the default one). Therefore, you should not modify the id manually before it is send to the server.
As the thread is diverted from its initial subject, please consider starting a new thread if further question raised.
Greetings,
Rosen
the Telerik team
arg.container.find("input[name='user_name']").val(customRowDataItem.user_name).change();
arg.container.find("input[name='group_name']").val(customRowDataItem.group_name).change();
arg.container.find("select[name='page_access_level_id']").val(customRowDataItem.page_access_level_id).change();
I found the answer on StackOverflow:
arg.model.set('user_name', customRowDataItem.user_name);
arg.model.set('group_name', customRowDataItem.group_name);
arg.model.set('page_access_level_id', customRowDataItem.page_access_level_id);
arg.model.set('page_name_id', customRowDataItem.page_name_id);
I also had to set each filed in the schema to editable:true (That's what the article said to do).
http://stackoverflow.com/questions/30419736/dynamic-default-value-for-kendo-grid
The Kendo UI Model field default value can be set to a JavaScript function. In this function, you may obtain the Kendo UI DropDownList instance and its value() and return it.
https://docs.telerik.com/kendo-ui/api/javascript/data/model#methods-Model.define
Let me know if you need more help.
Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Could you guys either update all the links in your forum or fix the SSL cert on your website: https://docs.telerik.com/
the "here" and "here" links require bypassing the invalid SSLs throughout your support site.
Thanks.
Hi, Matt,
Thank you for bringing this to our attention.
It is the old domain of the Kendo UI documentation that has an expired certificate. I have addressed the reported behaviour with the team that is responsible for this as it should be redirected globally.
Meanwhile, I have fixed these particular links from this forum post.
Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.