This is a migrated thread and some comments may be shown as answers.
Kendo Grid handling create/delete errors with popup editor
10 Answers 507 Views
This is a migrated thread and some comments may be shown as answers.
Iulian
Top achievements
Rank 1
Iulian asked on 11 Dec 2013, 01:07 PM
Hello,

I have a kendo grid using a popup editor that does a create/delete, both of them ending with errors.
I would like to handle both errors
1. When having an error on delete to prevent the row deleting from the grid
2. When having a create error to prevent the popup editor to close

Please see this fiddle: 
http://jsfiddle.net/andreigavrila/p49eV/2/

The second point works by default (so having an error on create does not close the popup)
The first point works by adding the error function and cancelingChanges
$('#grid').data("kendoGrid").cancelChanges();
, but adding that that breaks the popup (it now closes on error).

So I can have either one of my requirements, but not both in the same time.
I am kind of stuck.

I saw this 2 questions on kendo forums:
http://www.kendoui.com/forums/kendo-ui-complete-for-asp-net-mvc/grid/deleted-row-removed-from-grid-even-though-errors-returned-in-destroy-method.aspx
http://www.kendoui.com/forums/kendo-ui-framework/mvvm/handling-validation-errors-from-server-in-kendo-grid.aspx

But as you can see in the fiddle I can't make it both work on the same time

Thank you for your help

10 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 13 Dec 2013, 06:50 AM
Hi Lulian,

I suggest you to use an if condition in the error event handler to determine which of the two workarounds should be executed.
In this case the server should provide information about type of the error that occurred. You can retrieve the error status from error event arguments.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mike
Top achievements
Rank 1
answered on 19 May 2015, 09:59 PM
I have the same problem but I can't reliably determine just by looking at the error text whether I should cancelChanges on the grid or not. I need to have more context such as whether the error is occurring from within the popup or not, or what action caused it. At this point the only insight I have is by looking at e.sender._destroyed which my guess is bad form.
0
Alexander Valchev
Telerik team
answered on 21 May 2015, 09:02 AM
Hi Mike,

The error message is generated from the server. The server should include all the needed information about type of the error and which actions caused it.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Mike
Top achievements
Rank 1
answered on 21 May 2015, 03:06 PM
Let's say I have two MVC controller actions. One is in the context of a popup and one is not (e.g., one is involved in a create or update and one is involved in a delete). Both controller actions make the same preliminary Entity Framework call which throws an error. How am I supposed to know which controller action was involved, and hence whether I should execute cancelChanges on the grid? Since the controller actions are being called by the DataSource Read, Create, Update and Destroy, I would hope to be able to key off that information, not the host of errors that might be thrown by Entity Framework. Maybe I'm missing something and need an example.
0
Alexander Valchev
Telerik team
answered on 25 May 2015, 03:45 PM
Hello Mike,

You may use the parameterMap of the DataSource transport to add additional parameters to the request data or to set a ModelState error on the server that provides more information.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 10 Jul 2015, 10:24 AM
Isn't this all relying on the server to provide the information about the appropriate response to the error? What I want is for the server to tell me that there is an error, and it's then up to the client to determine the appropriate response (in this case, cancelChanges if the user has been trying to delete something, but not otherwise).
0
Alexander Valchev
Telerik team
answered on 14 Jul 2015, 07:21 AM
Hello Simon,

You may hook up to the error event of the DataSource and cancel the changes that the user has made.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 14 Jul 2015, 08:11 AM

Thanks Alexander.

My issue is that I can't find a way to tell which client operation led to the error. If they were deleting a row then I want to cancel changes and redisplay the row. But if they were updating or inserting, then I don't want to cancel the changes, giving them the opportunity of correcting the data. I can't even parse the error message (not that this is a good idea anyway), since the error I am handling here could occur as the result of either a delete or an insert.

 I'm hoping that I've missed something and there's a property in the error event that will give me the information I need!

0
Daniel
Telerik team
answered on 16 Jul 2015, 02:55 PM
Hello Simon,

I am afraid that there isn't a parameter in the error event argument that indicates which action has failed. A possible approach that I can suggest if the type cannot be returned in the errors from the server, is to use the requestStart event to save the last request type and use the saved value in the error event:
function onRequestStart(e) {
    this.lastRequestType = e.type;
}
 
function onError(e) {
    if (this.lastRequestType == "destroy") {
        this.cancelChanges();
    }
    ...
}


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 17 Jul 2015, 09:40 AM
Thanks - that's formed the basis of a solution for me.
Tags
Grid
Asked by
Iulian
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Mike
Top achievements
Rank 1
Simon
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or