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

How to cancel a remove event on a listview

5 Answers 667 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Volkan
Top achievements
Rank 1
Volkan asked on 30 Jan 2013, 11:42 PM
I have created a listview bound to a remote datasource.  I have added a delete button using the k-delete-button class, and clicking on the button does remove the item from the listview.  My question is can I optionally cancel the remove event?  My first assumption was that I would implement the remove event on the listView, could implement any needed business logic, and optionally cancel the remove operation.  I was able to catch the event and the model was passed with the record that was removed, but I can't seem to find any way to cancel the operation.  No matter what I do, the listview item that was removed does not return to the screen.

5 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 31 Jan 2013, 08:05 AM
Hello Volkan,

You can call preventDefault in order to prevent further execution of the handler. For example:
listview.bind("remove", function(e) {
 if(!confirm("Are you sure?)) e.preventDefault();
})


Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Volkan
Top achievements
Rank 1
answered on 31 Jan 2013, 03:45 PM
Thanks,

I did try that, but it appears that the item has already been removed from the listview before the execution of the remove event.  From what I can tell the preventDefault only prevents the DataSync event? 
0
Nikolay Rusev
Telerik team
answered on 01 Feb 2013, 10:08 AM
Hello Volkan,

Here is a working sample:
http://jsbin.com/oxeqik/3/edit

We are not sure how you observe described behavior.  Clicking cancel in the confirmation dialog prevent item remove.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dragan
Top achievements
Rank 1
answered on 12 Mar 2013, 09:01 AM
Nikolay,

What do you do if the server logic cannot delete the item for any reason? I think that is what Volkan is asking you about. When you click OK on that confirmation box, it will delete the item without taking care if the delete REALLY took place.

If you look at the code in js file, you will notice that this is what is happening at both grid and listview, items get removed once user clicks on that OK button in confirmation box. What would be the way to change that behavior at listview or grid?
0
Nikolay Rusev
Telerik team
answered on 13 Mar 2013, 01:39 PM
Hello Dragan,

If that's what you need you can handle DataSource.error event and call cancelChanges in order to revert back hidden items on error. 

Here is a sample demonstrating this: http://jsbin.com/oxeqik/12/edit

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