How to determine index of an item being dropped client side

4 posts, 0 answers
  1. Alice
    Alice avatar
    4 posts
    Member since:
    Aug 2015

    Posted 01 Oct 2015 Link to this post

    We have just started with a trial of Telerik tools for a new drag and drop playlist we will be implementing into our solution. We are tracking the movement and sorting of each item by its value, parent value and id and we will be tracking any changes in an array and then on save we will be using those references to build new playlists.

     

    The issue we are running into is getting the current index of the node when dropped on client side. We have used the OnClientNodeDropping but it doesnt seem to return the id of the item after it is dropped. Is there a different way we should be going about getting this? 

     

     

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    831 posts

    Posted 06 Oct 2015 Link to this post

    Hello,

    You can get the index of the source node (the node you are dragging and dropping) and the destination node (the node you drop onto) with the get_index() client side method. In a similar fashion using the corresponding methods (get_text(), get_value(), etc.) you can get the other properties of the source or destination item:
    function OnClientNodeDropping(sender, args) {
        var sourceItem = args.get_sourceNode();
        var sourceIndex = sourceItem.get_index();
     
        var destItem = args.get_sourceNode();
        var destIndex = destItem.get_index();
    }

    As for getting the item's ID, there is no client-side method that would allow you to get it as it is used internally for building the hierarchy (parent nodes -> child nodes). A possible workaround would be to add the id as a custom attribute to each item and you will be able to access it through the item's attributes collection.
     
    Regards,
    Ivan Danchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alice
    Alice avatar
    4 posts
    Member since:
    Aug 2015

    Posted 06 Oct 2015 Link to this post

    I need the new index of the item being dropped, not the node it is being dropped on's index. Is there anyway to get that? 
  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    831 posts

    Posted 08 Oct 2015 Link to this post

    Hello,

    The dropped node's new index will correspond to the number of child nodes the destination node contains, unless you are reordering the nodes after dropping.
    For example, if you drop node X on node Y and node Y does not have any child items the index of X will be 0. If node Y has 3 child nodes the index of X will be 3. You can get the child nodes count in the OnClientNodeDropping handler the following way:
    function OnClientNodeDropping(sender, args) {
        var destItem = args.get_destNode();
        var childrenCount = destItem.get_allNodes().length;
    }

    In the example above the value of "childrenCount" will correspond to the new node's index.

    Regards,
    Ivan Danchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top