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

UID is generated before onChange of ID

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 10 Feb 2014, 05:26 PM
I have a grid where for newly created items I autoincrement the ID field like this:

// use this to handle auto-increment for new rows
var current = -1;
function onChange(e) {
 
    if (e.action == "add") {
        var item = e.items[0];
 
        item.ID = current;
 
        current -= 1;
    }
}

The problem I am having is when I call addRow() the UID is generated based on an ID of 0, and not the ID that I create in the onChange event. This causes problems when trying do a dataSource.get(ID)...

// ID = -1
var item = dataSource.get(ID);
 
// UID = undefined because the UID was generated thinking it was an ID of 0, not -1
var uid = item.uid;

Any hints? This is making other operations on my grid impossible.

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 12 Feb 2014, 07:56 AM
Hello Jason,

Default value for number is `0` and that is what will be used when new model is instantiated, except if `defaultValue` for the field is defined.

You can find more details on model field definition here: Model definition.

Regards,
Nikolay Rusev
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
Jason
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or