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

[Solved] problem in destroying row in grid

1 Answer 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jochen
Top achievements
Rank 1
Jochen asked on 17 Dec 2014, 01:24 PM
Hello:
I have problem in destroying one row in grid.

Suppose I have one grid with dataSource well configured. In the dataSource.transport we defined read/update/destroy functions that can fetch data, update data and delete data in remote server individually.  the code looks like following

$("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: function (e) {
                            // fetch data from remote server                        
                        },
                        update: function (e) {
                            // update one record in remote server
                        },
                        destroy: function (e) {
                            // delete one record in remote server
                        }
                    },
                    pageSize: 10,                    
                    schema: {
                        model: {
                            id: "id",
                            fields: {
                                id: {editable: false, nullable: false},
                                value: {type: "string", editable: true, nullable: false}
                            }
                        }
                    }

                },
                pageable: {
                    input: false,
                    numeric: true
                },
                height: 400,
                scrollable: false,

                columns: [
                    {
                        field: "id", title: "id", width: "100px"
                    },
                    {
                        field: "value", title: "value"
                    },
                    {
                        command: [
                            {name:"edit"},
                            {name:"delete"}
                        ]
                    }
                ],
                editable: "inline"
            });

the question is if we click delete button on one row in grid, and this row will be removed from ui immediately and a delete request defined in dataSource.transport will be sent to remote server. If everything works fine, that's good, but what if remote server rejects the delete request for whatever reason. the result is the record was not deleted from server, but removed from UI. The expected result would be when delete button clicked, UI should wait until response from remote server, if OK, remote record from UI, else show error message

Thanks

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 19 Dec 2014, 08:07 AM
Hi Jochen,

The behaviour you described is expected by design. Kendo UI is not aware if the record has actually been removed on the server and the error occurred after this or the server has rejected the delete request. This is why the developer should handle the error event, decide what to do and explicitly say it.

In your particular case you may add an error event handler and call the cancelChanges method of the DataSource to discard the user change and bring back the row in the UI.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Jochen
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or