Selecting previous item after a remove

2 posts, 0 answers
  1. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2008

    Posted 24 Jul 2012 Link to this post

    Hello, I've got a listview whose template includes a button that causes removal of the clicked item from the listview.  I also followed another forum post explaining how to suppress the mouseclick event so that my button click event doesn't select the clicked item. 

    However, when the remove happens in my click handler via the listview.remove(item) method, it looks like the listview syncs to the datasource.  The problem is that when this occurs the listview appears to lose it's selection.  I'm guessing this is by design, but is there a way in which I can store the selected index before the remove and then reselect the item afterwards?  The main task is getting the selected index in my click handler.  I see a way to get the selected item using listView().select() but not the index.  After the rebind, if I try to pass this selected item into the select function it no longer finds it, so I guess it goes out of scope after the rebind. 

    Do you have any guidance for me?

    Thanks,
    Eric
  2. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2008

    Posted 24 Jul 2012 Link to this post

    Well I discovered a way to do this:

    1) Get the id of the selected item (where listView represent a reference to the listview object per the usual method):
    var selectedItem = listView.select()[0].id;

    2) The after the remove, find this item using jquery
    $("#" + selectedItem.id);

    3) and reselect it:
    listView.select(image);

    I did figure out how to get the selected index: listView.select().index() but didn't use it here.

    Thanks,
    Eric
  3. Kendo UI is VS 2017 Ready
Back to Top