How to cancel a remove event on a listview

6 posts, 1 answers
  1. Volkan
    Volkan avatar
    10 posts
    Member since:
    Jul 2011

    Posted 30 Jan 2013 Link to this post

    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.
  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 31 Jan 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Volkan
    Volkan avatar
    10 posts
    Member since:
    Jul 2011

    Posted 31 Jan 2013 Link to this post

    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? 
  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 01 Feb 2013 Link to this post

    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!
  6. Dragan
    Dragan avatar
    7 posts
    Member since:
    Feb 2013

    Posted 12 Mar 2013 Link to this post

    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?
  7. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 13 Mar 2013 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready