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

id field cannot be "id"

6 Answers 425 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Dean asked on 31 Jul 2015, 03:54 AM

I would like to refer you to this posthttp://www.telerik.com/forums/inline-editing-cancel-removes-the-row#gUEDci4cHEu8PsmAm4rhpg

It explains that the id ​field of a model cannot be set to "id" because it breaks the grid (clicking cancel deletes records). The post I have linked to was misunderstood by Nikolay Rusev who replied explaining case sensitivity - it has nothing to do with that. The fact is that either "id" is a reserved word ​that ​cannot be used by model fields or the grid has a bug.

I want this to either be officially recognized as a bug by the Kendo team (and fixed), or it should be properly documented that "id" cannot be used as a field name in a model. It has wasted too much of my time.

6 Answers, 1 is accepted

Sort by
0
Dean
Top achievements
Rank 1
answered on 31 Jul 2015, 03:57 AM
Sigh, the link "id field of a model" didn't work in my last post. It should link to: http://docs.telerik.com/kendo-ui/api/javascript/data/model#fields-id
0
Nikolay Rusev
Telerik team
answered on 04 Aug 2015, 06:02 AM

Hello Dean,

 

Actually the posts in the thread are quite correct. In the thread I explain few things:

 

 1. schema.model.id - is a must in order to have state tracking and to have all CRUD operations working correctly (link).

 

 2. the field which you define in the schema.model.id must be part of the model. In fact the default field is `id`. If you don't have `id` field in your model data you must specify which field defines uniquely the item (link).

 

 3. JavaScript is case sensitive and the user was incorrectly defined schema.model.id to refer, incorrectly,  to `id` field when in fact there is a `Id` field in this model data instead.

 

 

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dean
Top achievements
Rank 1
answered on 04 Aug 2015, 09:25 PM

Sorry Nikolay, but I think you've misunderstood me. The 3 points you've given are good, crystal clear and well understood. Even though my code adheres to them, the grid misbehaves - I'm convinced there is a bug. If I change the name of my "id" field to say "somethingOtherThanId" then it works. Same field, same data and same grid, the only change is what I've named the field used for the schema.model.id

So this doesn't work (yet it's correct code): 

schema: {
  model: {
    id: "id",
    fields: {
      id: { type: "number", validation: {required: true } }

 

This does work:

schema: {
  model: {
    id: "somethingOtherThanId",
    fields: {
      somethingOtherThanId: { type: "number", validation: {required: true } },

 

What I mean when I say the grid misbehaves is the grid deletes records when cancel is clicked. I'm not talking about cancelling a new record, I'm talking about editing an existing record and then clicking cancel.

 

0
Nikolay Rusev
Telerik team
answered on 06 Aug 2015, 01:03 PM

Hello Dean,

I'm not sure how to replicate this behavior. Take for example this online demo. It is using ProductID as a id field and canceling edit operation doesn't seem to remove the item.

Can you demonstrate your scenario in a runnable example?

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Adam
Top achievements
Rank 1
answered on 12 Aug 2019, 04:55 PM

Uh, yeah...

I wasted a lot of time on this too!

I wish I had figured this out sooner.

0
Viktor Tachev
Telerik team
answered on 14 Aug 2019, 11:06 AM

Hello,

 

Thank you for the feedback. We have updated the documentation so that it describes the specific behavior. The note is included in the article below: 

https://docs.telerik.com/kendo-ui/framework/datasource/crud#setting-the-schema

 

Regards, Viktor Tachev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Dean
Top achievements
Rank 1
Answers by
Dean
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Adam
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or