This question is locked. New answers and comments are not allowed.
Frank Michael
Top achievements
Rank 1
Frank Michael
asked on 18 May 2010, 02:56 PM
I am using a Grid with Ajax Binding and Client Edit.
When I insert a new record, I want to set a default value for a field. How can I do that, because there is no controller request.
When I insert a new record, I want to set a default value for a field. How can I do that, because there is no controller request.
9 Answers, 1 is accepted
0
Frank Michael
Top achievements
Rank 1
answered on 19 May 2010, 09:15 AM
Can you quickly tell my if my requirement is out of scope or in scope of
Telerik Grid?
0
Frank Michael
Top achievements
Rank 1
answered on 19 May 2010, 09:40 AM
I think I should be able to do this with jQuery
0
Frank Michael
Top achievements
Rank 1
answered on 19 May 2010, 03:07 PM
I wasn't able to do it. I am only a jQuery beginner and I can not invest too much time into it.
I suggest a Helper Function:
I suggest a Helper Function:
| c.Bound(r => r.RemainingHours).InsertDefaultValue(1); |
0
Frank Michael
Top achievements
Rank 1
answered on 20 May 2010, 02:23 PM
This question is still open.
I have applied for support tickets, but it is not yet active. So any help in the meanwhile is appreciated.
I have applied for support tickets, but it is not yet active. So any help in the meanwhile is appreciated.
0
Frank Michael
Top achievements
Rank 1
answered on 27 May 2010, 10:59 AM
You wrote:
"If you want to set default value for a grid editor you must provide an editor template for that column which contains some control with default value set. You may have to write some JavaScript in order to set the default value only if required."
If I have two problems with your proposal:
1) Number.ascx is defined as:
If I write this:
Then I have the problem that I have 1 as default value for all Numbers, which I do not want. I have two fields: RemainingHours and RemainingDays. I only want the default value in RemainingHours, not RemainingDays.
2.
If I define a new View RemainingHours.ascx containing the default value, I have to create so many templates for different fields and default values, although I would want them only for different types. At least, yes, this is a workaround. But I think in the future there should be a more elegant way.
"If you want to set default value for a grid editor you must provide an editor template for that column which contains some control with default value set. You may have to write some JavaScript in order to set the default value only if required."
If I have two problems with your proposal:
1) Number.ascx is defined as:
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<double>" %> |
| <%= Html.Telerik().NumericTextBox() |
| .Name(ViewData.TemplateInfo.HtmlFieldPrefix) |
| .Value(Model) |
| %> |
If I write this:
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<double>" %> |
| <%= Html.Telerik().NumericTextBox() |
| .Name(ViewData.TemplateInfo.HtmlFieldPrefix) |
| .Value(1) |
| %> |
2.
If I define a new View RemainingHours.ascx containing the default value, I have to create so many templates for different fields and default values, although I would want them only for different types. At least, yes, this is a workaround. But I think in the future there should be a more elegant way.
0
Frank Michael
Top achievements
Rank 1
answered on 27 May 2010, 11:01 AM
And there is another problem with 2:
The default value is then used always: even when editing and even if there already was another value. This does not work. So the approach 2. does not work as well.
The default value is then used always: even when editing and even if there already was another value. This does not work. So the approach 2. does not work as well.
0
Hello Frank Michael ,
Yes. That's why I wrote this "You may have to write some JavaScript in order to set the default value only if required.". You need to add a script block and set the value through JavaScript if such a value is not set.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Yes. That's why I wrote this "You may have to write some JavaScript in order to set the default value only if required.". You need to add a script block and set the value through JavaScript if such a value is not set.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Frank Michael
Top achievements
Rank 1
answered on 27 May 2010, 11:09 AM
But what does "value not set" mean, if it is a double type?
Just if value == 0 is not the answer, because it may be 0 intentionally.
So my problem is how do I transport the information from outside into the EditorTemplate, that the or a default value should be set?
Or, if I write the javascript not in the template, but in the view, then I have to distinguish if the form line is a create case or an update case.
Theoretically I might catch the add.. button click event. Is that the way to go?
Just if value == 0 is not the answer, because it may be 0 intentionally.
So my problem is how do I transport the information from outside into the EditorTemplate, that the or a default value should be set?
Or, if I write the javascript not in the template, but in the view, then I have to distinguish if the form line is a create case or an update case.
Theoretically I might catch the add.. button click event. Is that the way to go?
0
Hi Frank Michael ,
If you want to set default value use the UIHint to specify the editor for the particular type. Or capture the click event of the add/edit button, then find the required html element and set its value to whatever you want. If you choose that you need to use setTimeout in order for the editing UI to be created.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
If you want to set default value use the UIHint to specify the editor for the particular type. Or capture the click event of the add/edit button, then find the required html element and set its value to whatever you want. If you choose that you need to use setTimeout in order for the editing UI to be created.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.