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

KendoUI Grid with Remote Data Source Not Working

4 Answers 428 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Warren
Top achievements
Rank 1
Warren asked on 22 Sep 2012, 05:46 PM
Hello everyone,

I copied the demo grid source for the remote data, and when I click the add button and the popup form is filled out everything looks good.  If I click on the edit button or delete button the datasource is still calling the server with the create part of the transport and ignoring the update/destory.    How can I get this working?

dataSource = new kendo.data.DataSource({
                            transport: {
                                read:  {
                                    url: crudServiceBaseUrl,
                                    dataType: "jsonp"
                                },
                                update: {
                                    url: crudServiceBaseUrl + "?action=update",
                                    dataType: "jsonp",
                                    type: "POST"
                                },
                                destroy: {
                                    url: crudServiceBaseUrl + "?action=destroy",
                                    dataType: "jsonp"
                                },
                                create: {
                                    url: crudServiceBaseUrl + "?action=create",
                                    dataType: "jsonp",
                                    type: "POST"
                                },
                                parameterMap: function(options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return {models: kendo.stringify(options.models)};
                                    }
                                }
                            },
                          etc....
                        });

 $("#grid").kendoGrid({
                        dataSource: dataSource,
                        pageable: true
etc....
});

4 Answers, 1 is accepted

Sort by
0
Warren
Top achievements
Rank 1
answered on 24 Sep 2012, 02:05 AM
I added error with console.log to the datasource and changed it from jsonp to json and it works like a champ.
0
Neil
Top achievements
Rank 1
answered on 26 Sep 2012, 11:10 AM
I believe this is because JSONP only works for GET requests and not POST/PUT/DELETE. If you need cross domain JSON, have a look at CORS (Cross-Origin Resource Sharing) for your web service.

Thanks,

Neil.
0
Amol G
Top achievements
Rank 2
answered on 23 Nov 2012, 09:02 AM
Thanks Warren
Its works for me to get records but it was not calling data source update and delete methods. Please see below code

 $("#ColumnsGrid").kendoGrid({
                                                dataSource: {
                                                            transport: {
                                                                        read: {
                                                                                 url:"../MyController/Read",
                                                                                 dataType: "json",
                                                                                  type: "POST"
                                                                               },
                                                                        update: {
                                                                                   url:"../MyController/Update",
                                                                                   dataType: "json",
                                                                                    type: "POST"                                                                                   
                                                                                },
                                                                       destroy: {
                                                                                    url:"../MyController/Delete",
                                                                                    dataType: "json",
                                                                                     type: "POST"
                                                                                },
                                                                       parameterMap: function(options, operation) {                                                                                                                       if (operation !== "read" && options.models) {
                                                                                                                        return {models: kendo.stringify(options.models)};
                                                                                                                    }
                                                                                                                  }    
                                                              },
                                                            schema: {
                                                                       model: {                            
                                                                                 fields: {
                                                                                               ColumnID: { editable: false, nullable: true },
                                                                                               Column: { validation: { required: true } },
                                                                                               Operator: { type: "string", validation: { required: true} },                                     
                                                                                               Label: { type: "string", validation: { required: true } }
                                                                                          }
                                                                             }
                                                                   }
                                                        },
                                                pageable: true,     
                                                height:300,   
                                                change: onChange,                        
                                                dataBound: onDataBound,                    
                                                columns: [     
                                                            { field: "Operator", title: "Operator", width: "150px",editor: categoryDropDownEditor },                                               
                                                            { field: "Column", title:"Column Name", width: "150px" },
                                                            { field: "Label",  title: "Label" , width: "100px" },
                                                            {  command: ["edit", "destroy"], title: " ", width: "210px" }
                                                         ],
                                                editable: "inline"                            
                                            });          
Thanks,
Amol
0
Craig
Top achievements
Rank 1
answered on 06 Mar 2013, 09:47 PM
You need to define the ID field in the model.

e.g.
model: {    
id: "ColumnId",
 fields: {

                                                                                    
Tags
Grid
Asked by
Warren
Top achievements
Rank 1
Answers by
Warren
Top achievements
Rank 1
Neil
Top achievements
Rank 1
Amol G
Top achievements
Rank 2
Craig
Top achievements
Rank 1
Share this question
or