This is a migrated thread and some comments may be shown as answers.

[Solved] Programmatically update column's defaultValue

1 Answer 243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 16 Jan 2015, 09:18 AM
Hi,
I'm building a grid using the ASP.NET helpers, but that's unrelevant.

I'm performing CRUD operation over a DB where some tables starts with ID 0. As a result, I'm forced to set the DefaultValue for that column to -1, because the other numbers may be used for the table rows.
But actually for everytime the user wants to perform an insertion, i don't want to show the ugly "-1" as ID default value, but i would like to set the first available number or otherwise zero.

Is there a way to associate a function to return the defaultValue or to anyway change the default value in an elegant way?

Thanks

1 Answer, 1 is accepted

Sort by
1
Alexander Popov
Telerik team
answered on 20 Jan 2015, 08:04 AM
Hello Paolo,

Generally speaking, IDs should not be manually edited by the user - this is a task that should be performed on database or server-side level. Nevertheless you can use the Grid's edit event handler to set a value of your choice for the new items. For example: 
function onEdit(e) {
    if(e.model.isNew()){
       e.model.set("MyField", newValue);
    }
}


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Michele
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Share this question
or