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

CRUD Update fires more than one

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 26 Nov 2012, 12:17 PM
Yo,

I'm using the KendoGrid, and there's a problem in my CRUD process. When I'm clicking to update button after editing data (in popup mode) in first time, the ajax call and the update in server works fine. But when I'm trying to edit an another row, the update ajax call runs twice, for this row, and the previous row. Here's my code:

        var dataSource = new kendo.data.DataSource({
            transport: {
                create: {
                    url: GLOBALS.BASE_URL + "partner_editor_ajax/create",
                    dataType: "json",
                    type: "POST",
                    complete: function(e) {
                        dataSource.read();
                    }
                },                
                read:  {
                    url: GLOBALS.BASE_URL + "partner_editor_ajax/read",
                    dataType: "json",
                    type: "POST"          
                },
                update: {
                    url: GLOBALS.BASE_URL + "partner_editor_ajax/update",
                    dataType: "json",
                    type: "POST",
                    complete: function(e) {
                        e.preventDefault();
                    }          
                },
                destroy: {
                    url: GLOBALS.BASE_URL + "partner_editor_ajax/destroy",
                    dataType: "json",
                    type: "POST"
                }
            },
            pageSize: 30,
            batch: false,
            schema: {
                data: "results",
                total: "results_per_page",
                errors: "errors",
                model: {
                    id: "_id",
                    fields: {
                        _id: { editable: false, nullable: false },
                        employeesNumber: { editable: false, nullable: true },
                        leaderName: {
                            editable: true, 
                            validation: {
                                required: true,
                                pattern: "(.+){2,50}"
                            }
                        },
                        mailingAddress: { 
                            editable: true, 
                            validation: {
                                required: true,
                                pattern: "(.+){2,}"
                            }
                        },
                        name: { 
                            editable: true, 
                            validation: {
                                required: true,
                                pattern: "(.+){2,}"
                            } 
                        },
                        taxNumber: { 
                            editable: true, 
                            validation: { 
                                required: true,
                                pattern: "[0-9]{6,20}"
                            } 
                        },
                        type: { 
                            defaultValue: { value: "personal", text: "personal"},
                            editable: true, 
                            validation: { 
                                required: true,
                                pattern: "(.+){2,}"
                            } 
                        },
                        website: { editable: true }
                    }
                }
            }
        });


        $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: true,
            height:  ($(window).height() - $("#header").height() - 4),
            toolbar: ["create"],
            columns: [              
                { 
                    field: "employeesNumber",
                    title: Localization.get_localized_text("employees_number"),
                    width: "50px"
                },
                { 
                    field: "leaderName",
                    title: Localization.get_localized_text("leader_name"),
                    width: "150px"
                },                
                { 
                    field: "mailingAddress",
                    title: Localization.get_localized_text("mailing_address"),
                    width: "200px"
                },                
                { 
                    field: "name",
                    title: Localization.get_localized_text("name"),
                    width: "150px"
                },                
                { 
                    field: "taxNumber",
                    title: Localization.get_localized_text("taxNumber"),
                    width: "150px"
                },                
                { 
                    field: "type",
                    title: Localization.get_localized_text("type"),
                    editor: typeDropDownEditor,
                    width: "100px"
                },                
                { 
                    field: "website",
                    title: Localization.get_localized_text("website"),
                    width: "100px"
                },         
                { 
                    command: ["edit"], title: " ", width: "60px" 
                },         
                { 
                    command: ["destroy"], title: " ", width: "70px" 
                }
            ],
            editable: {
                mode: "popup"
            }
        });        


Please help, what is the problem here?

Thank you in advance,
R

1 Answer, 1 is accepted

Sort by
0
Accepted
Tetha
Top achievements
Rank 1
answered on 28 Nov 2012, 02:15 PM
Hi Robert,
your CREATE request returns the saved entities?
Below an example using asmx service and Entity Framework.
If you don't do this the grid doesn't recognize the newly added entities and for each subsequent requests resend all the entities to the CREATE method.
I hope this helps you,
Mirko
[WebMethod]
public IEnumerable<News> Create( IEnumerable<News> news )
{
    if ( news.Count() > 0 )
    {
        var n = news.FirstOrDefault();
 
        db.News.Add( n );
        db.SaveChanges();
    } 
    return news;
}
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Tetha
Top achievements
Rank 1
Share this question
or