Hi!
Is there any way to add dynamic default values? When I push the "Add row" button a new row with a new default value (max value + 1) for count column should be added.
Example:
.ToolBar(toolbar => {
toolbar.Create().Text("Add row");
})
...
.Model(model => {
model.Id(n => n.ID);
model.Field(c => c.count).DefaultValue(<this value needs to be max value + 1>);
model.Field(c => c.count).Editable(false);
})
I have tried to adding an event on .Events( e => e.Change("MyFunction")) but the row adding is done after MyFunction event is fired.
/Malte
Is there any way to add dynamic default values? When I push the "Add row" button a new row with a new default value (max value + 1) for count column should be added.
Example:
.ToolBar(toolbar => {
toolbar.Create().Text("Add row");
})
...
.Model(model => {
model.Id(n => n.ID);
model.Field(c => c.count).DefaultValue(<this value needs to be max value + 1>);
model.Field(c => c.count).Editable(false);
})
I have tried to adding an event on .Events( e => e.Change("MyFunction")) but the row adding is done after MyFunction event is fired.
/Malte
6 Answers, 1 is accepted
0
Hi Staffan,
Kind Regards,
Vladimir Iliev
the Telerik team
Current approach to use the edit event is valid and you can use it to change the default value for given field in the following way:
function
onEdit(e) {
//execute your custom logic to get the max value
var
maxValue = 5;
//check if record is new
if
(e.model.isNew()) {
//set the required field value
e.model.set(
"OrderCount"
, maxValue + 1);
}
}
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Richard van Diggelen
Top achievements
Rank 1
answered on 22 Nov 2013, 03:32 AM
Hi Vladimir,
Thanks for the solution. I used the same code and it worked. but in my case, I want that field to be readonly, so the default value is calculated from the max +1 and set as new record inserted, displayed in grid, but user shouldn't be able to change that.
I set the 'Editable(false)' to the model, but it actually breaks that code and new value doesn't applied. However the "DefaultValue" applied in Model wil continue working
ex:
model.Field(p => p.SequenceNumber).Editable(false); //There is a js function which filles that field but it fails to update
model.Field(p => p.ApprovalStateID).Editable(false).DefaultValue(1); // This works!
Any thoughts?
Thanks for the solution. I used the same code and it worked. but in my case, I want that field to be readonly, so the default value is calculated from the max +1 and set as new record inserted, displayed in grid, but user shouldn't be able to change that.
I set the 'Editable(false)' to the model, but it actually breaks that code and new value doesn't applied. However the "DefaultValue" applied in Model wil continue working
ex:
model.Field(p => p.SequenceNumber).Editable(false); //There is a js function which filles that field but it fails to update
model.Field(p => p.ApprovalStateID).Editable(false).DefaultValue(1); // This works!
Any thoughts?
0
Hi Steffan,
You should leave the field editable and use for example the Edit event of the Grid to find the needed input in the container and disable / remove it. Please check the example below:
Kind Regards,
Vladimir Iliev
Telerik
You should leave the field editable and use for example the Edit event of the Grid to find the needed input in the container and disable / remove it. Please check the example below:
function
onEdit(e) {
e.container.find(
"[name=fieldName]"
).hide();
}
Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Patrick
Top achievements
Rank 1
answered on 06 Mar 2016, 06:57 PM
Are there limitations to using this technical? It does not work for me trying to set the foreign key column using the value from the grid above.
0
Hello Patrick,
No there are no limitations of using this approach - that why in current case I would suggest to inspect the editor template using your browser dev tools and adjust the jQuery selector in order to hide the correct element.
Regards,
Vladimir Iliev
Telerik
No there are no limitations of using this approach - that why in current case I would suggest to inspect the editor template using your browser dev tools and adjust the jQuery selector in order to hide the correct element.
Regards,
Vladimir Iliev
Telerik
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 Feedback Portal
and vote to affect the priority of the items
0
Randy
Top achievements
Rank 1
answered on 24 Mar 2017, 11:42 AM
Excellent. That works, thank you!