0

I'm using a Kendo Grid with a datasource using type Odata. I have troubles creating a new row in the database from the datasource. This is my datasource code:

var ds = new kendo.data.DataSource({
            type: "odata",
            transport: {
                read: {
                    url: baseUrl,
                    dataType: "json"
                },
                update: {
                    url: function (data) {
                        return baseUrl + "('" + data.ID_Agenzia + "')";
                    }
                },
                create: {
                    url: baseUrl
                },
                destroy: {
                    url: function (data) {
                        return baseUrl + "('" + data.ID_Agenzia + "')";
                    }
                }
            },
            schema: {
                model: {
                    id: "ID_Agenzia",
                    fields: {
                        ID_Agenzia: { type: "string" },
                       // etc... my other fields omitted for brevity.
                    }
                }
            },
            pageSize: 20,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true
        });

Then I tried a simple grid with the automatic toolbar Create (pretty standard, I think I can omit the code), using this DS.

As far as I understood, Kendo got a method "isNew" to discern between Create/Update and it checks if the ID is === to the default value. All the examples I found googling around, were using the ID as a numeric incremental value... But in my table the ID is a String (obviously unique) that needs to be inserted by the user!!

Hoping I've explained myself well, the issue should be clear: If the user inserts the ID, the datasource won't recognize that it's a Create operation... Otherwise if I forbit the manual ID insert, the create will work... but the row will be inserted in the DB with the default value (empty string) and this is wrong!

How can I solve this? Thanks.

[EDIT] Addictional info: I'm using latest version of Kendo-ui and Odata 2.0

MaHaZaeL
  • 59
  • 10
  • You can add a new column having same value as Id column. When adding a new record add your unique Id in that new column and forget original Id column, that will have default value. And at server use that new column. I know that's not a good solution but a workaround. – Ankush Jain Sep 15 '14 at 13:22
  • Thanks for answer, I thought about a thing like that. But you meant adding a new column in the database (that could be problematic) or only in the grid? – MaHaZaeL Sep 15 '14 at 13:54
  • No you dont need to add column at db. Add an field at kendo datasource and the same property in business object,which you are using at server side – Ankush Jain Sep 15 '14 at 17:34

0 Answers0