Limiting the number of items allowed in a listview sortable

2 posts, 0 answers
  1. Luke
    Luke avatar
    1 posts
    Member since:
    Nov 2014

    Posted 28 Nov 2014 Link to this post


    I have two listviews that are linked together as linked list sortables. The drag and drop functionality is working really well but I need to be able to limit the number of items in the second listview so that when a user tries to drag an item into the second listview it cancels the move event and displays a message. I can't find an example of this anywhere.

    Thanks in advance,
  2. Alexander Valchev
    Alexander Valchev avatar
    2887 posts

    Posted 02 Dec 2014 Link to this post

    Hi Luke,

    Thank you for contacting us.

    In order to achieve this you may hook up to the beforeMove event and call the preventDefault method.
    function beforeMove(e) {
      if (e.list.element.attr("id") === "sortable-left" && e.sender.items().length >= 4) { //if the items is greater than 4
        e.preventDefault(); //cancel the move action
        $("h4").text("Maximum number of items in the list is reached").css("color", "red"); //alert the user

    For your convenience I prepared a small example:

    I hope this information will help.

    Alexander Valchev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top