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

How to add row to CRUD datasource using MVVM?

8 Answers 347 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 16 Apr 2012, 11:19 PM
I have defined a kendo datasource with transport methods (create, read, update, and destroy), as well as a schema definition:

            var dataSource = new kendo.data.DataSource({
            transport: {
                create: {
                    url: "/api/Prospects",
                    type: "POST"
                },
                
read: "/api/Prospects",
                update: {
                    url: "/api/Prospects",
                    type: "PUT"
                },
                destroy: {
                    url: "/api/Prospects",
                    type: "DELETE"
                }
            },
            schema: {
                model: {
                    id: "ProspectId",
                    fields: {
                        ProspectId: {
                            editable: false,
                            nullable: true
                        },
                        FirstName: { type: "string" },
                        LastName: { type: "string" },
                        EmailAddress: { type: "string" },
                        ProspectTypeId: { type: "number" },
                        ProspectStatusId: { type: "number" }
                    }
                },
                type: "json"
            }
        });

My form elements contain appropriate data-bind attributes to form elements, and I am calling kendo.bind passing the form and datasource as parameters. The goal is that the form is used for both adding and editing records.

I am not sure how to write the code to initialize the form for adding a new record to the datasource.

I've been unsuccessful finding an example to do this on the kendo website. Can you help?

Thanks,
Gary

8 Answers, 1 is accepted

Sort by
0
Joshua
Top achievements
Rank 1
answered on 17 Apr 2012, 05:57 PM
I am also interested in a solution to this particular problem. I have taken the same steps as the OP, and noted that updates to my form appear to update the elements in the DataSource model. However, calling .sync() doesn't appear to do anything. Can we get some input on this problem?
0
Ä m o l
Top achievements
Rank 2
answered on 25 Apr 2012, 04:24 PM
I am also having the same problem.... I am expecting quick answer from Kendo Team
0
Lee
Top achievements
Rank 1
answered on 26 Apr 2012, 10:59 AM
Me too, I have read everything there is in the documentation and forums on this but cannot get anything to work.  There are no real working examples that I can find.
0
Tess
Top achievements
Rank 1
answered on 11 May 2012, 11:22 AM
Full disclosure:  I am a total Kendo newbie.

Gary, you said: "I am calling kendo.bind passing the form and datasource as parameters."   I think that's your trouble.  kendo.bind wants a kendo.observable passed in -- not a datasource.  Frustrating -- I know!

The example that finally got me unstuck is here: http://demos.kendoui.com/web/mvvm/remote-binding.html

See how they pass the datasource into a field in the viewModel object, and then bind the viewModel to the form?  I think that's what you want to do!

I have tested this out, and it seems to work.  Let me know if you need more help!

Tess
0
Devon
Top achievements
Rank 1
answered on 14 Aug 2012, 10:52 AM
I'm having the same issue as Joshua. 

My datasource is being updated locally but calling dataSource.sync() does nothing. The request isn't being sent to the server or anything.
0
Ross
Top achievements
Rank 1
answered on 09 Sep 2012, 04:55 PM
I totally agree, found lots of examples that add or update locally but no examples I've found actually call an mvc controller on the server side. The few examples I've found don't work because of a sql express provider error. Disappointing!
0
Christophla
Top achievements
Rank 1
answered on 10 Oct 2012, 09:03 PM
I've been struggling with this for weeks. Honestly, there are too many ways to utilize Kendo and not nearly enough examples.

I'm tired of reading "how to populate a grid".
0
Ross
Top achievements
Rank 1
answered on 10 Oct 2012, 10:14 PM
Hey all,

I got an example working that actually hits a controller and a dbase.  See attached and hopefully they will help you all out.

Ross
Tags
MVVM
Asked by
Gary
Top achievements
Rank 1
Answers by
Joshua
Top achievements
Rank 1
Ä m o l
Top achievements
Rank 2
Lee
Top achievements
Rank 1
Tess
Top achievements
Rank 1
Devon
Top achievements
Rank 1
Ross
Top achievements
Rank 1
Christophla
Top achievements
Rank 1
Ross
Top achievements
Rank 1
Share this question
or